Wednesday, June 09, 2021

AWS Labmda

Looking at my  lambda error. Dose aws lambda support node.js ES6?

 

2021-06-09T00:50:21.381Z    undefined    ERROR    Uncaught Exception     {
    "errorType": "Error",
    "errorMessage": "Must use import to load ES Module: /var/task/lambda.js\nrequire() of ES modules is not supported.\nrequire() of /var/task/lambda.js from /var/runtime/UserFunction.js is an ES module file as it is a .js file whose nearest parent package.json contains \"type\": \"module\" which defines all .js files in that package scope as ES modules.\nInstead rename lambda.js to end in .cjs, change the requiring code to use import(), or remove \"type\": \"module\" from /var/task/package.json.\n",
    "code": "ERR_REQUIRE_ESM",
    "stack": [
        "Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /var/task/lambda.js",
        "require() of ES modules is not supported.",
        "require() of /var/task/lambda.js from /var/runtime

...
 

In the package.json,

{

    "type":"module"

}

This is how I get my ES6 import syntax work in node.js, but not serverless.

To resolve this issue, install esm package npm install esm.
Also remove "type":"module" in package.json.



No comments: