美文网首页
electron使用worker_threads的限制

electron使用worker_threads的限制

作者: ape_caesar | 来源:发表于2022-03-22 15:54 被阅读0次

    为什么我的项目在electron中用不了node的新api---worker_threads ?

    这个文章中的论点发表于2022-03-22年,electron最新版本17,后续可能会有不同

    Renderer进程中使用

    throw Error: the v8 platform used by this instance of node does not support creating workers
    electron的渲染进程挂载的node vm实例没有能力创建 线程

    Main进程中使用

    报错 can't find XXXX in /Users/XXX/application-XXX/app.asar/electron/worker_process.js
    // it cannot be possible to load modules from worker when using worker_threads from the main process electron
    主进程中是对require做过特殊处理来处理app.asar的, 而在worker_threads线程中识别不了app.asar中的module,所以无法在打包后加载第三方的module,除非你自己把所有的依赖都加到unpacked里面,太麻烦了,或者你在worker里不需要第三方的库

    相关链接 [https://github.com/electron/electron/issues/18540]
    (https://github.com/electron/electron/issues/18540)

    相关文章

      网友评论

          本文标题:electron使用worker_threads的限制

          本文链接:https://www.haomeiwen.com/subject/mjvfjrtx.html