gpt4 book ai didi

javascript - Node : bad option: --experimental-worker

转载 作者:搜寻专家 更新时间:2023-10-31 23:49:53 47 4
gpt4 key购买 nike

我正在尝试在 node.js 中使用 worker_threads。

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!');
}

我将以上代码保存在 index.js 中,并在终端上运行 node --experimental-worker index.js。我收到以下错误:

node: bad option: --experimental-worker.

我在我的 mac 中安装了 Node 的 v8.16.0

最佳答案

Worker nodejs v10.5.0 中添加了类。

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

nodejs v12.x稳定,无需--experimental-worker

即可使用

下载:nodejs

版本管理器:nvm

关于javascript - Node : bad option: --experimental-worker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58154066/

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