Javascript AWS SAM本地启动api:设置lambda nodejs 12.x标志(例如——实验模块)?
我在nodejs服务器上使用ES6模块语法: package.jsonJavascript AWS SAM本地启动api:设置lambda nodejs 12.x标志(例如——实验模块)?,javascript,node.js,aws-lambda,es6-modules,aws-sam-cli,Javascript,Node.js,Aws Lambda,Es6 Modules,Aws Sam Cli,我在nodejs服务器上使用ES6模块语法: package.json "type": "module" 我(成功)将服务器作为本地nodejs进程运行。例如: "scripts": { "dev": "npm outdated ; nodemon --experimental-modules --inspect=4001 main.local.js" } 问题:如果我通过sam本地启动服务器: "scripts": { "dev-sam": "sam local start-api
"type": "module"
我(成功)将服务器作为本地nodejs进程运行。例如:
"scripts": {
"dev": "npm outdated ; nodemon --experimental-modules --inspect=4001 main.local.js"
}
问题:如果我通过sam本地启动服务器:
"scripts": {
"dev-sam": "sam local start-api --skip-pull-image",
}
我得到一个错误:
Warning: require() of ES modules is not supported.
require() of /var/task/main.js from /var/runtime/UserFunction.js is an ES module file
as it is a .js file whose nearest parent package.jsoncontains "type": "module" which
defines all .js files in that package scope as ES modules.
Instead rename main.js to end in .cjs, change the requiring code to use import(), or
remove "type": "module" from /var/task/package.json.
我的结论是:我需要告诉nodejs运行时启用实验性es6模块支持
问题:我该怎么做
已尝试(不工作):
不能将参数传递给lambda环境。您需要使用transpiler。使用webpack或类似的transpiler编译lambda函数。很抱歉延迟。谢谢你把我送到正确的方向。
"scripts": {
"dev-sam": "sam local start-api --experimental-modules --skip-pull-image",
}