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 a require('some_module')
in the worker process the process crashes with the error.
Cannot find module 'some_module'.
The cjs loader cannot find my module apparently. But when I make the same require
call from the renderer process, I'm able to require
the module.
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.
A few observations
__dirname
in the rendered process resolves toroot/node_modules/electron/dist/resources/electron.asar/renderer
and in the worker process resolves to
root/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
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.
Meta: Electron version = "4.0.0", platform = "win32", arch = "x64", node version = "v10.11.0"
Any help in this regard would be appreciated.