Reputation: 155
I am not getting any error in local with node-fetch in the package.json also have node-fetch dependencies but when I deployed in aws lambda then this dependencies not found. import fetch from 'node-fetch';
{
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module 'node-fetch'\nRequire stack:\n- /var/task/query1.js\n- /var/task/query1Main.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
"trace": [
"Runtime.ImportModuleError: Error: Cannot find module 'node-fetch'",
"Require stack:",
"- /var/task/query1.js",
"- /var/task/query1Main.js",
"- /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:999:30)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
" at Module.load (internal/modules/cjs/loader.js:863:32)",
" at Function.Module._load (internal/modules/cjs/loader.js:708:14)",
" at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)",
" at internal/main/run_main_module.js:17:47"
]
}
Upvotes: 2
Views: 9787
Reputation: 1483
I had the same issue using Node version 18.x
and fixed after downgrading to 16.x
This can be done in the lambda page -> scroll down to Runtime settings
I hope you already resolved the issue but I'm posting this in case someone else finds it useful.
Upvotes: 0
Reputation: 171
You have to declare external packages as layers for a lambda https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html
Upvotes: 2