Search code examples
javascriptelectronworker-thread

Shared worker working before packing app, but not working after (electron)


I have an electron app where I am trying to push some CPU intensive tasks to a worker thread. This works well when I start the app using npm start, but after packing the app (with electron-packager with --asar) the worker thread appears to stop working. I am loading the worker thread like so:

const workerThread = new SharedWorker(path.join(__dirname, "JS/JS_MainWindow/worker.js"));

I am very confused about what could be causing this, but could it maybe be that the appl is being packaged into an ASAR folder? I am very confident I have the path correct for loading the worker file as I am loading several other images with the sameish path.


Solution

  • So this error was caused by a certain module I was requiring within my worker thread. For some reason, this certain module doesn't work post packaging.The path was indeed correct and workers apparently do work post packaging using "same" path as before packaging (ex: "C:\FOD\FOD-JS\fodGUI-win32-x64\resources\app.asar\src\JS\JS_MainWindow\worker.js").