Try to run ES module in a lambda function #13494
Labels
functions
Issues tied to the functions category
pending-response
Issue is pending response from the issue author
pending-triage
Issue is pending triage
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
20.10.0
Amplify CLI Version
12.8.2
What operating system are you using?
Mac
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No
Describe the bug
I try to run a function in lambda but it doesn't work.
I read some artices about it. Add type:module to the package.json, change extension or change it custom.js / custom.cjs... I tried many combinaisons in local and hosting env.
Here is my code
and my package.json
{
"name": "acgaPreSignup",
"type": "module",
"version": "2.0.0",
"description": "Lambda function generated by Amplify",
"main": "index.js",
"license": "Apache-2.0",
"devDependencies": {
"@types/aws-lambda": "^8.10.92"
},
"dependencies": {
"node-fetch": "^3.3.2",
"stripe": "^14.9.0"
}
Error displayed : "PreSignUp failed with error require is not defined in ES module scope, you can use import instead This file is being treated as an ES module because it has a '.js' file extension and '/var/task/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.."
Expected behavior
custom.js interpreted as .cjs file.
cf. :
https://aws.amazon.com/fr/blogs/compute/using-node-js-es-modules-and-top-level-await-in-aws-lambda/
Reproduction steps
Do what is described in the bug.
Project Identifier
No response
Log output
Additional information
No response
Before submitting, please confirm:
The text was updated successfully, but these errors were encountered: