Question(题)
I'm trying to use web workers in electron.(我正在尝试在电子领域使用网络工作者。)
So far I'm able to instanciate the worker process from the renderer process, but when I try to do arequire('some_module')
in the worker process the process crashes with the error.(到目前为止,我能够从渲染器进程实例化工作进程,但是当我尝试在工作进程中执行require('some_module')
,该进程将因错误而崩溃。)
Cannot find module 'some_module' .(找不到模块'some_module' 。)
The cjs loader cannot find my module apparently.(cjs加载器显然找不到我的模块。)
But when I make the samerequire
call from the renderer process, I'm able to require
the module.(但是,当我从渲染器过程中进行相同的require
调用时,我可以require
该模块。)
I've followed all the steps mentioned here .(我已按照此处提到的所有步骤进行操作。)
Also I've set the optionnodeIntegrationInWorker: true
and I can make require
calls to node inbuilt modules like fs
with no problems.(另外,我还设置了选项nodeIntegrationInWorker: true
并且可以nodeIntegrationInWorker: true
require
对诸如fs
类的节点内置模块require
调用。)
A few observations(一些观察)
__dirname
in the rendered process resolves to(呈现过程中的__dirname
解析为)root/node_modules/electron/dist/resources/electron.asar/renderer(根目录/node_modules/electron/dist/resources/electron.asar/renderer)
and in the worker process resolves to(并在工作程序中解决)
root/node_modules/electron/dist/resources/electron.asar/worker(根目录/node_modules/electron/dist/resources/electron.asar/worker)
as far as I've done the reading the require function should be able to find my module in the node_modules dir which is parent to both the renderer and worker dir(就我所做的阅读而言,require函数应该能够在node_modules目录中找到我的模块,该目录是渲染器目录和worker目录的父目录)
A quick look at the
process
global in the worker reveals thatprocess.type
is equalsworker
whileprocess.argv[1]
is equals--type=renderer
which I find strange.(快速查看workerprocess
全局process
,发现process.type
等于worker
而process.argv[1]
等于--type=renderer
,我觉得很奇怪。)
Meta : Electron version = "4.0.0", platform = "win32", arch = "x64", node version = "v10.11.0"(Meta :电子版本=“ 4.0.0”,平台=“ win32”,arch =“ x64”,节点版本=“ v10.11.0”)
Any help in this regard would be appreciated.(在这方面的任何帮助将不胜感激。)
ask by Nishkal Kashyap translate from so