serverless-optimizer-plugin
serverless-optimizer-plugin copied to clipboard
error with optimized lambda
I get this error on a lambda function when it has been optimized by this plugin. Without the plugin, the function works. I'm using the 'test' button from within the AWS console to produce this error:
{
"errorMessage": "Cannot find module './aes'",
"errorType": "Error",
"stackTrace": [
"Function.Module._resolveFilename (module.js:338:15)",
"Function.Module._load (module.js:280:25)",
"Module.require (module.js:364:17)",
"require (module.js:380:17)",
"i (/var/task/ivr/selection/handler.js:1:497)",
"/var/task/ivr/selection/handler.js:1:688",
"/var/task/ivr/selection/handler.js:12:25267",
"Array.map (native)",
"Object.a.exports (/var/task/ivr/selection/handler.js:12:25244)",
"o (/var/task/ivr/selection/handler.js:12:25428)"
]
}
I'm not sure how to debug this. But I can gather more info if you ask for something in particular.
I'm also getting an error when trying to use optimizer with my project.
{
"errorMessage": "Cannot find module '\/usr\/lib\/node_modules\/aws-sdk\/apis\/metadata.json'",
"errorType": "Error",
"stackTrace": [
"Function.Module._resolveFilename (module.js:338:15)",
"Function.Module._load (module.js:280:25)",
"Module.require (module.js:364:17)",
"require (module.js:380:17)",
"i (\/var\/task\/accounts\/register\/handler.js:1:497)",
"\/var\/task\/accounts\/register\/handler.js:1:688",
"n (\/var\/task\/accounts\/register\/handler.js:3:27116)",
"Object.i [as services] (\/var\/task\/accounts\/register\/handler.js:3:27572)",
"Object.<anonymous> (\/var\/task\/accounts\/register\/handler.js:6:1621)",
"Object..\/api_loader (\/var\/task\/accounts\/register\/handler.js:6:1806)"
]
}
The endpoints that fail with this message do not rely directly on the aws-sdk. Instead they use dynamodb-doc. Disabling optimizer fixes the problem.
Excluding aws-sdk from the optimzer fixed my issue.
"custom":
{
"optimize":
{
"exclude": ["aws-sdk"]
}
}
I'm getting a similar error when trying to import the "mongodb" module:
{"errorMessage":"Cannot find module './binary_parser'","errorType":"Error","stackTrace":["Function.Module._load (module.js:276:25)","Module.require (module.js:353:17)","require (internal/module.js:12:17)","o (/var/task/_serverless_handler.js:1:497)","/var/task/_serverless_handler.js:1:688","/var/task/_serverless_handler.js:1:16480","Array.forEach (native)","Object.a.10../bson (/var/task/_serverless_handler.js:1:16454)","o (/var/task/_serverless_handler.js:1:637)"]}
Unfortunately, excluding that module isn't an option for me. It's a needed dependency.
I'm having the same issue but when I exclude it and deploy there's no issue running import on the lambda O_o