ImportModuleError when executing lambdas
See original GitHub issueWhen I add the es-build plugin to my serverless.yml file and deploy to AWS, I get the following issue when triggering a lambda called InternalConfig
:
{
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module 's_internalConfig'\nRequire stack:\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
"stack": [
"Runtime.ImportModuleError: Error: Cannot find module 's_internalConfig'",
"Require stack:",
"- /var/runtime/UserFunction.js",
"- /var/runtime/index.js",
" at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
" at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
" at Object.<anonymous> (/var/runtime/index.js:43:30)",
" at Module._compile (internal/modules/cjs/loader.js:1072:14)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)",
" at Module.load (internal/modules/cjs/loader.js:937:32)",
" at Function.Module._load (internal/modules/cjs/loader.js:778:12)",
" at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)",
" at internal/main/run_main_module.js:17:47"
]
}
I get the same issue for all my lambdas deployed through serverless when using serverless-esbuild
For context, the InternalConfig lambda is defined in the serverless.yml
file as follows:
internalConfig:
handler: './src/handlers/internal-config.main'
events:
- http:
method: get
path: /internal/config/{serviceName}
- http:
method: post
path: /internal/config/{serviceName}
What’s weird is this error does not exist if I swap out the serverless-esbuild
plugin for another zero-config typescript support plugin like serverless-plugin-typescript
.
Any ideas as to why this might be happening?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7
Top Results From Across the Web
Resolve the "Unable to import module" error for Lambda code ...
I receive the "Unable to import module" error when I try to run my AWS Lambda code in Node.js. Short description. You typically...
Read more >"Runtime.ImportModuleError" trying to access npm package in ...
I was zipping a file containing my lambda instead of just my lambdas root. This was causing the lambda to look for my...
Read more >Lambda fails: "Runtime.ImportModuleError: Error: Cannot find ...
RUN rm -rf node_modules RUN npm install CMD serverless deploy. The lambda's stack trace is as follows: { "errorType": "Runtime.
Read more >How to Solve a AWS Lambda error - Runtime.ImportModuleError
ImportModuleError: Error: Cannot find module 'jmespath'. AWS Lambda scripts written in nodejs8 were deprecated. You run the same scripts via ...
Read more >AWS Lambda – cannot find module (based on handler)
Error in the Execution Result. <pre> Response: { "errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module 'decode-verify-jwt'", ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You are right, declaring winston logger as an external package in my case worked correctly. Thanks! 🙇
Hi i ran into the same problem. Esbuild does not bundle objects outside the handler (if for example, You want to initialise something and cache it between invocations)
A workaround is to initialise your code in a handler, which is sometimes not a good option cc @samchungy