electron使用worker_threads的限制

为什么我的项目在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的限制)