New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to use NodeJS worker_threads module #18540
Comments
Having the same issue with Electron 4.x.x and Node 12.4. Same behavior and setup. Have you found a fix for this? I've tried:
I've switched to using a edit: @sofianguy maybe you can lead us in the right direction, or give us a yes/no as to whether this is working in v4 or 5 |
AFAIK Electron ship its own node fork, so your local 12.4 doesn't really matter.
No, still waiting for response. There is pinned discussion #18397 which might be relevant somehow. |
Having the same issue with Electron 5.0.6 and Windows 10 :( |
Still no updates I still can not use threads in my electron app :( |
I tested it on - Electron 4, 5, 6 and even 7 .... |
i have this problem too |
Is there any chance of some statement from electron team? It's been months now (half year #17030) |
@SaltFish001 And what happens when you try to spawn a worker? |
It's work. |
sorry, it's seems no working.The process ended and no error was reported |
I've tried it before even posting this issue. It doesn't change anything. Experimental flag for worker module was only required in node v11 if I remember correctly. |
Working on this now - just got #20416 up as a partial starter fix :) |
This comment has been minimized.
This comment has been minimized.
@durasj oh derp yes thanks, updated! |
Small update - still working on this! it's related-but-different-than the Thanks for your patience, all 😁 |
I manage to make it work during dev and local production mode. I can use But app in
Very strange, seems compressing things into dmg breaks something. I have tried electron 8 and electron 9.1.0 Seems in "real" production mode, script in worker_thread can't use electron's require hook, so it can't find dependences in asar. |
Without looking very closely, this sounds very similar to a problem I encountered last week here In an electron packaged app, the This might be what your
|
I tried @dsteinman My Solution: I'm using electron-builder
wow, our seems If you miss one of the dep of dep, you will get MODULE_NOT_FOUND error too. worker manager const WIKI_WORKER_PATH = isDev
? path.resolve(__dirname, './wiki-worker.js')
: path.resolve(process.resourcesPath, 'app.asar.unpacked', 'wiki-worker.js');
const WIKI_WATCHER_WORKER_PATH = isDev
? path.resolve(__dirname, './watch-wiki-worker.js')
: path.resolve(process.resourcesPath, 'app.asar.unpacked', 'watch-wiki-worker.js');
|
I've made it works with Electron 9.x.x, however something weird is happening. The thread is making some sqlite queries and some intensive CPU tasks, until here is fine, however, when all the tasks finishes and the thread terminates (which should happen), the whole electron app simply crash. |
@LBRGeorge I run into this once, where I set worker.on('exit', code => {
if (code !== 0)
logger.warn(
`WikiWatcher ${wikiRepoPath} Worker stopped with exit code ${code}, this also happen normally when you delete a workspace.`,
loggerMeta,
); Electron just crush and I see the log get You can try winston's |
Hey folks - i understand that there's still active discussion in this thread, and insofar as it helps folks i encourage it to continue. However, this issue was opened as a reflection of the fact that |
This solution works for me as well I was not able to use worker_threads with the following configuration: I've used Electron Workers described here. Tasks processing is x2 faster now. I had a lot of |
@User0111 Actually I move to electron-forge, and use But it takes me a long time refactor my code to electron-forge + typescript. And maybe it is because I upgraded to |
Electron really need to add more support for |
@m4heshd Yes, but I finally make it worked... My latest solution includes:
|
That's great. Unfortunately I cannot afford the time for any major refactoring right now. I'm just using my workers and dependencies unpacked for the moment. But love to move to a solid solution in the near future. |
@linonetwo Thank you for your help. I have used the asar.unpacked trick and it worked like a charm. However, I am very disappointed that |
@linonetwo Thanks for the help. The mentioned solution did work but my worker is also using 'electron-store' which internally uses 'electron' Module. 'electron' needs to be mentioned in the dev-dependecies and I am not able to unpack the modules mentioned in the dev-dependencies using "asarUnpack" in package.json. Any workaround for this ? `error Error: Cannot find module 'electron'
|
@JaspreetChhabra I think code in worker don't have access to electron modules, because electron module only accessible from electron main thread (not any worker thread). A workaround may be passing signal to trigger things in main thread and return data back to the worker thread. You may use threads plugin to simplify this, it supports rxjs, so passing things here and there is not that terrible.
@Coukaratcha I'm currently not unpacking everything, I only unpack as need. https://github.com/tiddly-gittly/TidGi-Desktop/blob/master/docs/Development.md#how-to-add-dependency-that-used-in-a-worker_thread It makes building complex a bit, but it works and not increasing too much bundle size. well... 74M after install, but when zipped, no much , I think... See https://github.com/tiddly-gittly/TidGi-Desktop/releases TidGi-darwin-x64-0.7.7.zip 119 MB |
@linonetwo thanks for your solution. do you know if electron has made any progress on this matter? It has been two years |
I don't think electron will do anything new on this, because worker_thread is working with simple npm dependency. It depends on the npm package, if it use But I'm not sure now, because @giladgd say it is possible to locate |
@linonetwo Thanks for reply. In my case, I have an SDK, the SDK calls a .dll based on ffi-napi, I configured SDK externals in webpack, and move the SDK to asar.unpacked folder, which runs well in main thread; |
Issue Details
v5.0.2
Windows 10
Expected Behavior
On app ready start nodejs worker which consoles string.
Actual Behavior
App crash immediately after run
To Reproduce
Additional Information
I used electron-forge to quick build app.
The text was updated successfully, but these errors were encountered: