Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AWS SAM本地启动api:设置lambda nodejs 12.x标志(例如——实验模块)?_Javascript_Node.js_Aws Lambda_Es6 Modules_Aws Sam Cli - Fatal编程技术网

Javascript AWS SAM本地启动api:设置lambda nodejs 12.x标志(例如——实验模块)?

Javascript 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

我在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 --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",
}