electron-builder: javaScript error occurred in the main process
Version 21.2.0
- Target: Windows x64
My Electron app runs fine using electron from the command line, but after I’ve built it from an executable and try to run it I get:
[Window Title]
Error
[Main Instruction]
A JavaScript error occurred in the main process
[Content]
Uncaught Exception:
Error: The specified module could not be found.
\\?\C:\Users\username\AppData\Local\Temp\808c0bf6-a0f1-4211-a312-7c0cce29173a.tmp.node
at process.func (electron/js2c/asar.js:140:31)
at process.func [as dlopen] (electron/js2c/asar.js:140:31)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:922:18)
at Object.func (electron/js2c/asar.js:140:31)
at Object.func [as .node] (electron/js2c/asar.js:149:18)
at Module.load (internal/modules/cjs/loader.js:735:32)
at Module._load (internal/modules/cjs/loader.js:648:12)
at Module._load (electron/js2c/asar.js:717:26)
at Function.Module._load (electron/js2c/asar.js:717:26)
at Module.require (internal/modules/cjs/loader.js:775:19)
[OK]
I don’t know how to reproduce the error yet. Does anyone know why the app is attempting to load a module from AppData\Local? What module is this? How do I debug this problem?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18
Your app is trying to run a
.nodefile from the%temp%directory. The reason behind this issue is that Windows cannot runnode|dll|exeutablefiles from theasarpackage => so it copies them to%temp%and tries to execute them there.To fix this, add this to your
electron-builderconfigurationI have the same error

A JavaScript error occurred in the main process Uncaught Exception: Error: Cannot find module '/media/sf_linux-desktop/vue-electron-linux-x64/resources/app/background.js' at Module._resolveFilename (internal/modules/cjs/loader.js:972:15) at Function.n._resolveFilename (electron/js2c/browser_init.js:249:921) at Object. (electron/js2c/browser_init.js:185:3470) at Object../lib/browser/init.ts (electron/js2c/browser_init.js:185:3714) at webpack_require (electron/js2c/browser_init.js:1:128) at electron/js2c/browser_init.js:1:1200 at electron/js2c/browser_init.js:1:1267 at NativeModule.compileForInternalLoader (internal/bootstrap/loaders.js:277:7) at NativeModule.compileForPublicLoader (internal/bootstrap/loaders.js:219:10) at loadNativeModule (internal/modules/cjs/helpers.js:24:9)"asarUnpack": ["**/*.node"],is add this?I eventually discovered this issue is caused by a custom native node module I had created. If a native module fails to load for a myriad of reasons it will present with:
Error: The specified module could not be found.In my case there was a missing dependency the native node module required.
I have a similar error.
https://github.com/justadudewhohacks/opencv4nodejs/issues/707
but the
doesn’t help.
I fixed it yes, it was a configuration mistake. When I tried to build for windows I had an error coming from missing modules. When googling the error I found a solution which was to put
externals: [nodeExternals()],into my webpack configuration, which I did.So this just told webpack to ignore the modules and to bundle the app without them. And that’s why I had this missing module error.
At the end, I removed this line and went digging into the original problem, which I finally solved after a few days. I don’t know if this can help you, good luck anyway.
Same error here. Except that I don’t use the missing module anywhere. And when I add it to my dependencies, same result. Same error on Ubuntu and Windows10.