节点:错误选项:--experimental-worker

use*_*454 4 javascript worker-thread node.js

我正在尝试在node.js.

const { Worker, isMainThread, parentPort } = require('worker_threads');
if (isMainThread) {
    // This code is executed in the main thread and not in the worker.

    // Create the worker.
    const worker = new Worker(__filename);
    // Listen for messages from the worker and print them.
    worker.on('message', (msg) => { console.log(msg); });
} else {
    // This code is executed in the worker and not in the main thread.

    // Send a message to the main thread.
    parentPort.postMessage('Hello world!');
}
Run Code Online (Sandbox Code Playgroud)

我将上面的代码保存index.jsnode --experimental-worker index.js在终端上运行。我收到以下错误:

节点:错误选项:--experimental-worker。

v8.16.0的 mac 上安装了 node。

Est*_*iaz 7

Worker在V10.5.0的NodeJS添加类。

要使用--experimental-worker至少需要 nodejs v10.5.0

使用nodejs v12.x它是稳定的,可以在没有--experimental-worker

下载:nodejs

版本管理器:nvm