Using ES Modules breaks when a directory with the same name as the module exists
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 35/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- À l'abandon
- Stack technique
- node.js, typescript
- Domaine
- backend
Piste de recherche
Lisez src/UserFunction.js autour des lignes 73 et 133-174, puis reproduisez le problème avec la configuration décrite de package.json, hello-world.js et hello-world/ en utilisant le runtime Node.js 20 en mode verbose. C’est terminé lorsque le handler se charge correctement lorsqu’un répertoire porte le même nom que le module, sans l’ImportModuleError signalé.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- TypeScript
- Étoiles
- 224
- Forks
- 60
- Merge moyen
- 26 min
- PR mergées (30 j)
- 2
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de aws/aws-lambda-nodejs-runtime-interface-client
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 20/100
aws/aws-lambda-nodejs-runtime-interface-client#198 · 3 commentaires · 6 réactions ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
aws/aws-lambda-nodejs-runtime-interface-client#195 · 12 réactions ·
-
bug
aws/aws-lambda-nodejs-runtime-interface-client#170 · 15 commentaires · 6 réactions · 1 personne assignée ·
-
AWS Inspector findings for curl Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 38/100
aws/aws-lambda-nodejs-runtime-interface-client#159 · 2 réactions ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 42/100
aws/aws-lambda-nodejs-runtime-interface-client#145 · 1 commentaire · 6 réactions ·
Toutes les issues de aws/aws-lambda-nodejs-runtime-interface-client
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
ontola/atomic-server#1625 ·
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
melgarafael/DeskcommCRM#1451 ·
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
-
bug via-triage
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
bot:ai-assisted component:compact-js status:untriaged
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
midnightntwrk/midnight-sdk#403 ·