gpt4 book ai didi

javascript - AWS SAM 本地 start-api : Set lambda nodejs 12. x 标志(例如 --experimental-modules)?

转载 作者:行者123 更新时间:2023-12-02 21:34:58 25 4
gpt4 key购买 nike

我在我的 Nodejs 服务器上使用 ES6 模块语法:

package.json

"type": "module"

我(成功)将我的服务器作为本地 Nodejs 进程运行。例如:

"scripts": {
"dev": "npm outdated ; nodemon --experimental-modules --inspect=4001 main.local.js"
}

问题:如果我通过 sam local 启动服务器:

"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模块支持。

问题:我该怎么做?

尝试过(不起作用):

"scripts": {
"dev-sam": "sam local start-api --experimental-modules --skip-pull-image",
}

最佳答案

您无法将参数传递给 lambda 环境。您需要使用转译器。使用 webpack 或类似的转译器编译 lambda 函数。

关于javascript - AWS SAM 本地 start-api : Set lambda nodejs 12. x 标志(例如 --experimental-modules)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60522540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com