babel-node --experimental-worker app.js
Using this command for starting my project in development mode. Output is:
error: unknown option--experimental-worker'
config .babelrc:
{ "presets": [ ["env", { "targets": { "node": "current" } }], "stage-0", "flow" ], "plugins": [ "transform-decorators-legacy", "transform-flow-strip-types" ] }
This flag is needed to use worker threads. Using babel 6.26
I just ran into this today and replied to the issue on GitHub here. I've pasted my fix below:
I was using Nodemon, and it turns out that there's an option to include environment variables as
NODE_OPTIONSin thenodemon.jsonfile. 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_threadsinto a normal NodeJS app:
- Set up Nodemon
- Add a
nodemon.jsonfile to the root folder (example here)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.
The idea is to split your command into two phases:
Phase 1:
babel app.js --out-file app-compiled.js
And phase 2:
node --experimental-worker app-compiled.js
In npm scripts you can then combine the two:
"scripts": {
"pre-build": "babel ./app.js --out-file ./app-compiled.js",
"serve": "yarn pre-build && node --experimental-worker ./app-compiled.js"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With