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

主进程中是对require做过特殊处理来处理app.asar的, 而在worker_threads线程中识别不了app.asar中的module,所以无法在打包后加载第三方的module,除非你自己把所有的依赖都加到unpacked里面,太麻烦了,或者你在worker里不需要第三方的库

修改于2023-11-21我发现thread_worker在主进程中是可以访问到第三方库的

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容