I'm getting this error when I upload and test my AWS Lambda function:
{
"errorMessage": "Cannot find module 'elasticsearch'",
"errorType": "Error",
"stackTrace": [
"Function.Module._load (module.js:276:25)",
"Module.require (module.js:353:17)",
"require (internal/module.js:12:17)",
"Object.<anonymous> (/var/task/PublishElasticsearch.js:17:21)",
"Module._compile (module.js:409:26)",
"Object.Module._extensions..js (module.js:416:10)",
"Module.load (module.js:343:32)",
"Function.Module._load (module.js:300:12)",
"Module.require (module.js:353:17)"
]
}
and the line of code that require()
s the module:
var elasticsearch = require('elasticsearch')({
host: config.ElasticHost
});
The function runs successfully the only issue is requiring my module.
I run npm install
in the function directory and my ZIP that I upload is structured like this:
PublishElasticsearch.zip
PublishElasticsearch.js
node_modules
elasticsearch
Does anyone know why I would be getting this error?
I had all modules listed under devDependencies. Moving everything over to dependencies solved it for me.
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