I am working with aws lambda using serverless framework, I changed the runtime from nodejs8.10
to nodejs10.x
, then I got an errortrace,
{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'jmespath'","stack":["Runtime.ImportModuleError: Error: Cannot find module 'jmespath'"," 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:36:30)"," at Module._compile (internal/modules/cjs/loader.js:701:30)"," at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)"," at Module.load (internal/modules/cjs/loader.js:600:32)"," at tryModuleLoad (internal/modules/cjs/loader.js:539:12)"," at Function.Module._load (internal/modules/cjs/loader.js:531:3)"," at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)"," at startup (internal/bootstrap/node.js:283:19)"]}
What is the cause of this issue and how can get it fixed?
I hit the same problem Error: Cannot find module 'jmespath'
and solved it.
Do you use aws-sdk
via node_modules? like follows
var aws = require('aws-sdk');
If so you just remove aws-sdk from node_modules.
remove aws-sdk for yarn
yarn remove aws-sdk
remove aws-sdk for npm
npm uninstall aws-sdk
aws-sdk
has been included to lambda since nodejs10.
see: https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
In the root serverless project folder
npm i --save <npm module name missing>
Try to put ./
in front of your module name. I changed my name from require("xxx")
to require("./xxx")
and it worked again. In my case, the local module file i wanted to add (xxx.js
) is on the same level as the index.js
file.
I'd also like to add that as a preliminary step before adjusting your path, check and verify your dependencies listed in your package.json(s) files.
I've seen this error "Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'something' occur in the aws cloudwatch logs.
It happened because my project has multiple subprojects/subfolders with their own package.json files. Ensure that module is properly referenced in the subproject's package.json.
In local dev, you might have the dependency cited in your base/global package.json, and thinking it works -- but when you deploy the lambda the npm install that occurs during build does not include the newly required module because its not referenced in the local subproject's package.json.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With