gpt4 book ai didi

node.js - 将标志 `--experimental-worker` 与 babel-node 一起使用

转载 作者:行者123 更新时间:2023-12-01 22:47:16 25 4
gpt4 key购买 nike

babel-node --experimental-worker app.js

使用此命令以开发模式启动我的项目。输出是:

error: unknown option--experimental-worker'

配置.babelrc:

{ "presets": [ ["env", { "targets": { "node": "current" } }], "stage-0", "flow" ], "plugins": [ "transform-decorators-legacy", "transform-flow-strip-types" ] }

使用工作线程需要此标志。使用 babel 6.26

最佳答案

我今天刚遇到这个问题并在 GitHub 上回复了这个问题 here .我在下面粘贴了我的修复:

I was using Nodemon, and it turns out that there's an option to include environment variables as NODE_OPTIONS in the nodemon.json file. This did the trick for me:

{
"watch": ["server"],
"ext": "js",
"env": {
"NODE_OPTIONS": "--experimental-worker"
},
"exec": "babel-node server/server.js"
}

How to integrate Nodemon + worker_threads into a normal NodeJS app:

  1. Set up Nodemon
  2. Add a nodemon.json file to the root folder (example here)
  3. Add this to nodemon.json:

    "env": { "NODE_OPTIONS": "--experimental-worker" }

If you're setting up Nodemon for the first time, I found this tutorial very helpful.

关于node.js - 将标志 `--experimental-worker` 与 babel-node 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52391418/

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