Open OscarSaharoy opened 8 months ago
This doesn't work. I tried this in Lambda and got this:
2024-04-05T06:10:36.182Z undefined ERROR Uncaught Exception
{
"errorType": "Runtime.UserCodeSyntaxError",
"errorMessage": "SyntaxError: Cannot use import statement outside a module",
"stack": [
"Runtime.UserCodeSyntaxError: SyntaxError: Cannot use import statement outside a module",
" at _loadUserApp (file:///var/runtime/index.mjs:1084:17)",
" at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)",
" at async start (file:///var/runtime/index.mjs:1282:23)",
" at async file:///var/runtime/index.mjs:1288:1"
]
}
This doesn't work. I tried this in Lambda and got this:
2024-04-05T06:10:36.182Z undefined ERROR Uncaught Exception { "errorType": "Runtime.UserCodeSyntaxError", "errorMessage": "SyntaxError: Cannot use import statement outside a module", "stack": [ "Runtime.UserCodeSyntaxError: SyntaxError: Cannot use import statement outside a module", " at _loadUserApp (file:///var/runtime/index.mjs:1084:17)", " at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)", " at async start (file:///var/runtime/index.mjs:1282:23)", " at async file:///var/runtime/index.mjs:1288:1" ] }
Ah thanks for giving it a go anyway, I think its working for me though, I made a new node.js version 20.x Lambda function and copied the code from the index.js file in this branch into index.mjs in the lambda code editor. And when I clicked save and then deploy and test it seemed to work, and I didnt get that error?
I just tried this code with Node 20: it works great! I created one index.mjs
file in the root of new Lambda for the code.
This works with Node v20 in AWS Lambda. For people who get an error:
"SyntaxError: Cannot use import statement outside a module",
File must have .mjs extension, not .js
Hi, thanks so much for this project :) I have just set this up in node 20 and got it working with these changes so I thought people might find it useful. I can make changes + additions if it would be helpful but just putting this PR in for reference!