最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

节点:错误的选择:

运维笔记admin16浏览0评论

节点:错误的选择:

节点:错误的选择:

我正在尝试在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。我收到以下错误:

节点:错误的选择:-experimental-worker。

我的Mac中已安装v8.16.0节点。

回答如下:

Worker类已在nodejs v10.5.0中添加。

要使用Worker,至少需要nodejs v10.5.0

具有--experimental-worker,它很稳定,可以在没有nodejs v12.x的情况下使用

下载:--experimental-worker

版本管理器:nodejs

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论