Using ES Modules breaks when a directory with the same name as the module exists
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- node.js, typescript
- Área
- backend
Línea de trabajo
Lee src/UserFunction.js alrededor de las líneas 73 y 133-174, y reproduce el problema con la configuración descrita de package.json, hello-world.js y hello-world/ usando el runtime Node.js 20 en modo verbose. Se considera hecho cuando el handler se carga correctamente si un directorio comparte el nombre del módulo, sin el ImportModuleError reportado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
If you setup a project with the following structure:
"type": "module"in package.json- A
hello-world.jsfile - A
hello-world/folder - Use
hello-world.lambdaHandleras your module/handler - Enable verbose mode, e.g. with
ENV AWS_LAMBDA_RUNTIME_VERBOSE 1in a Docker container usingpublic.ecr.aws/lambda/nodejs:20, so you can see the verbose messages
This is the resulting log.
START RequestId: 99e7b316-ab71-4bd2-8aed-85df8b0aeaaf Version: $LATEST
2023-12-13T01:13:42.274Z undefined INFO RUNTIME LOADER Try loading as commonjs: hello-world with paths: , /var/task
2023-12-13T01:13:42.275Z undefined INFO RUNTIME LOADER Try loading as commonjs: /var/task/hello-world
2023-12-13T01:13:42.276Z undefined INFO RUNTIME LOADER globalPaths ["/opt/nodejs/node20/node_modules","/opt/nodejs/node_modules","/var/runtime/node_modules","/var/runtime","/var/task","/root/.node_modules","/root/.node_libraries","/var/lang/lib/node"]
2023-12-13T01:13:42.276Z undefined ERROR Uncaught Exception {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module '/var/task/hello-world'\nRequire stack:\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module '/var/task/hello-world'","Require stack:","- /var/runtime/index.mjs"," at _loadUserApp (file:///var/runtime/index.mjs:1087:17)"," at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)"," at async start (file:///var/runtime/index.mjs:1282:23)"," at async file:///var/runtime/index.mjs:1288:1"]}
13 Dec 2023 01:13:42,288 [ERROR] (rapid) Init failed error=Runtime exited with error: exit status 129 InvokeID=
2023-12-13T01:13:42.351Z undefined INFO RUNTIME LOADER Try loading as commonjs: hello-world with paths: , /var/task
2023-12-13T01:13:42.352Z undefined INFO RUNTIME LOADER Try loading as commonjs: /var/task/hello-world
2023-12-13T01:13:42.353Z undefined INFO RUNTIME LOADER globalPaths ["/opt/nodejs/node20/node_modules","/opt/nodejs/node_modules","/var/runtime/node_modules","/var/runtime","/var/task","/root/.node_modules","/root/.node_libraries","/var/lang/lib/node"]
2023-12-13T01:13:42.353Z undefined ERROR Uncaught Exception {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module '/var/task/hello-world'\nRequire stack:\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module '/var/task/hello-world'","Require stack:","- /var/runtime/index.mjs"," at _loadUserApp (file:///var/runtime/index.mjs:1087:17)"," at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)"," at async start (file:///var/runtime/index.mjs:1282:23)"," at async file:///var/runtime/index.mjs:1288:1"]}
END RequestId: a879dd58-2f3f-458a-9911-dbb92b552019
REPORT RequestId: a879dd58-2f3f-458a-9911-dbb92b552019 Init Duration: 0.29 ms Duration: 156.42 ms Billed Duration: 157 ms Memory Size: 128 MB Max Memory Used: 128 MB
{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module '/var/task/hello-world'\nRequire stack:\n- /var/runtime/index.mjs","trace":["Runtime.ImportModuleError: Error: Cannot find module '/var/task/hello-world'","Require stack:","- /var/runtime/index.mjs"," at _loadUserApp (file:///var/runtime/index.mjs:1087:17)"," at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)"," at async start (file:///var/runtime/index.mjs:1282:23)"," at async file:///var/runtime/index.mjs:1288:1"]}
Cause
Before trying to load a module an extensionless import is attempted. Because fs.existsSync does not differentiate between a directory and a file it returns true and a require on the directory is attempted without any try catch.
Background
I was working on a project using multiple ESModules based lambda functions. The code was transpiled from TypeScript and because some code needed to be shared between functions I had a hello-world.js in the root that was export * from './dist/hello-world/src/app.js'; to so the lambda function ran off the transpiled code.
- Lenguaje dominante
- TypeScript
- Estrellas
- 224
- Forks
- 60
- Merge medio
- 26 min
- PR fusionados (30 d)
- 2
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de aws/aws-lambda-nodejs-runtime-interface-client
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
aws/aws-lambda-nodejs-runtime-interface-client#198 · 3 comentarios · 6 reacciones ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
aws/aws-lambda-nodejs-runtime-interface-client#195 · 12 reacciones ·
-
bug
aws/aws-lambda-nodejs-runtime-interface-client#170 · 15 comentarios · 6 reacciones · 1 asignado ·
-
AWS Inspector findings for curl Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 38/100
aws/aws-lambda-nodejs-runtime-interface-client#159 · 2 reacciones ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
aws/aws-lambda-nodejs-runtime-interface-client#145 · 1 comentario · 6 reacciones ·
Todos los issues de aws/aws-lambda-nodejs-runtime-interface-client
Issues similares
-
blocklist removal
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
MetaMask/eth-phishing-detect#296544 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
pastelsky/bundlephobia#1122 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
category/development priority/P2 scope/file-operations scope/testing type/enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100