Closed Fransebas closed 4 years ago
I'm using electron": "^8.0.0
and node version v12.15.0
Hiya - this module bundles Web Workers, not Node workers_threads. I think it might be possible to add an option for outputing worker_threads, but I worry that { type: 'module' }
is misleading for that use-case, since Node does not actually have any plans to support a "type" option that I'm aware of.
FWIW it seems like in Electron you're getting a Web Worker. For a lot of use-cases, especially when you've already bundled source with Webpack, that might be a reasonable approach.
One thing you could try to get this working without any library changes would be to import the correct worker implementation yourself:
const { Worker } = require('worker_threads');
const worker = new Worker("./worker.js", { type: "module" });
I'm actually going to close this issue since it's a duplicate of #10 - we can continue discussion there!
Hey @developit - I'm also facing this issue. The scenario isn't to use worker_threads, it's to use a Worker with a NodeJS context in Electron: https://www.electronjs.org/docs/tutorial/multithreading#multi-threaded-nodejs
My use-case is to use OffscreenCanvas within a Worker, which is impossible in a worker_therad as OffscreenCanvas is a browser API, not a NodeJS one. However I need access to NodeJS to use a native module (Electron docs say to avoid doing this, but so-far it has been successful).
I'm trying to migrate from worker-loader
, but facing the same Module not found: Error: Can't resolve 'child_process'
as @Fransebas had back in Feb.
@2xAA did did you manage to workaround this issue? Im facing it too..
@edenhermelin Unfortunately not. I wrote some pretty awful __dirname
hacks around a library we were consuming to make it work with worker-loader
.
Worked for a while but has broken with Electron 11 for some reason.
I'm trying to solve this exact issue also.
@edenhermelin or @2xAA did either of you figure this out?
I also followed the directions in #75, which DOES let me create a worker from the main
process, but not from the renderer
process.
@developit can we re-open this issue? It is not the same as creating a node worker.
What this is about:
@edenhermelin or @2xAA did either of you figure this out?
Nope, sorry. This was my awful workaround for the library I was consuming. Might be quite specific, however.
Hi, amazing library. I'm having problems because when I create a simple worker like this one:
If I create the worker like this:
var worker1 = new Worker('./workerTest.js');
It works, but when I create the worker like this:
var worker2 = new Worker('./workerTest.js', { type: 'module' });
It shows this message
Module not found: Error: Can't resolve 'child_process'
meaning that theworker2
doesn't includeNode.js
. I don't know if I should include another option apart fromtype: 'module'
or if this is not supported by this library.Also, I can't use
worker1
method because the real worker is more complex and has a lot of imports.