Creating a worker on electron doesn't include Node.js
See original GitHub issueHi, amazing library. I’m having problems because when I create a simple worker like this one:
// node.js library
var child_process = require('child_process');
console.log("This is a testing string");
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 the worker2
doesn’t include Node.js
. I don’t know if I should include another option apart from type: '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.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9
Top Results From Across the Web
NodeJS modules not supported in Electron Web Workers
This error leads me to believe that Electron NodeJS modules are not supported in web workers. The Electron documentation here says otherwise, ...
Read more >Multithreading | Electron
Any native Node.js module can be loaded directly in Web Workers, but it is strongly recommended not to do so. Most existing native...
Read more >Why the Hell Would I Use Node.js? A Case-by-case Tutorial
Node.js can solve I/O scaling, but was not created to compute scaling problems. Learn why and when to use Node.js in this case-by-case...
Read more >Cluster | Node.js v19.3.0 Documentation
A Worker object contains all public information and method about a worker. In the primary it can be obtained using cluster.workers . In...
Read more >Node.js multithreading: Worker threads and why they matter
So, at this point, many people might think our solution should be to add a new module in the Node.js core and allow...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 sameModule not found: Error: Can't resolve 'child_process'
as @Fransebas had back in Feb.Nope, sorry. This was my awful workaround for the library I was consuming. Might be quite specific, however.
https://github.com/vcync/modV/commit/81eac0a13017f776af913449fad8c06a7c408821#diff-7b4e11be73603a3ee2c4d37bd49f053930d6056507a005e5639cea7c15686d5fR7-R14