Enigmatic-Smile/serverless-plugin-optimize

Cannot find module... Error when looking up module saml2-js in node_modules directory

Opened this issue · 1 comments

Hi people!

I'm trying to deploy a lambda function to use it in CloudFront. The problem with the lambda function is the size of the package is over the 1mb, that is not supported in lambda@edge.

I decided to use serverless-plugin-optimize to minify my lambda package, but there is some trouble with modules that are importe using the node_modules directory. For example, the module saml2-js use an index.js file that import the exported module from another javascript file. This behavior repeats with other modules in the same condition.

2020-03-04T02:27:14.705Z	undefined	ERROR	Uncaught Exception 	
{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module '/var/task/_optimize/<function>/node_modules/saml2-js/lib-js/saml2'\nRequire stack:\n- /var/task/_optimize/<function>/facade.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module '/var/task/_optimize/<function>/node_modules/saml2-js/lib-js/saml2'",
        "Require stack:",
        "- /var/task/_optimize/<function>/facade.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:955:30)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)",
        "    at Module.load (internal/modules/cjs/loader.js:811:32)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:723:14)",
        "    at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)",
        "    at internal/main/run_main_module.js:17:11"
    ]
}

Are there any settings I can use?

Thanks in the advance!

Any update on this?