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

Most upvoted comments

Your app is trying to run a .node file from the %temp% directory. The reason behind this issue is that Windows cannot run node|dll|exeutable files from the asar package => so it copies them to %temp% and tries to execute them there.

To fix this, add this to your electron-builder configuration

"asarUnpack": ["**/*.node"]

I 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) image "asarUnpack": ["**/*.node"], is add this? image

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.

electron/js2c/asar.js:138 Uncaught (in promise) Error: The specified module could not be found.
\\?\C:\Users\User\AppData\Local\Temp\b3ccaeda-cfb0-43e5-868c-cab1254fdf7d.tmp.node
    at process.func (electron/js2c/asar.js:138)
    at process.func [as dlopen] (electron/js2c/asar.js:138)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:828)
    at Object.func (electron/js2c/asar.js:138)
    at Object.func [as .node] (electron/js2c/asar.js:147)
    at Module.load (internal/modules/cjs/loader.js:645)
    at Function.Module._load (internal/modules/cjs/loader.js:560)
    at Module.require (internal/modules/cjs/loader.js:685)
    at require (internal/modules/cjs/helpers.js:16)
    at Object.<anonymous> (C:\Users\User\AppData\Local\Programs\Labmate\resources\app.asar\node_modules\opencv4nodejs\lib\cv.js:58)
    at Object.<anonymous> (C:\Users\User\AppData\Local\Programs\Labmate\resources\app.asar\node_modules\opencv4nodejs\lib\cv.js:69)
    at Module._compile (internal/modules/cjs/loader.js:786)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:798)
    at Module.load (internal/modules/cjs/loader.js:645)
    at Function.Module._load (internal/modules/cjs/loader.js:560)
    at Module.require (internal/modules/cjs/loader.js:685)

https://github.com/justadudewhohacks/opencv4nodejs/issues/707

but the

"asarUnpack": ["**/*.node"]

doesn’t help.

Any fixes?

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.

A JavaScript error occurred in the main process
Uncaught Exception:
Error: Cannot find module '@babel/runtime/helpers/asyncToGenerator'
Require stack:
- /usr/lib/myapp/resources/app/.webpack/main/index.js
- 
    at Module._resolveFilename (internal/modules/cjs/loader.js:887:15)
    at Function.n._resolveFilename (electron/js2c/browser_init.js:257:1128)
    at Module._load (internal/modules/cjs/loader.js:732:27)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
    at Module.require (internal/modules/cjs/loader.js:959:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at /usr/lib/rekordtools/resources/app/.webpack/main/index.js:1:710
    at /usr/lib/rekordtools/resources/app/.webpack/main/index.js:1:3484
    at Object.<anonymous> (/usr/lib/rekordtools/resources/app/.webpack/main/index.js:1:3505)
    at Module._compile (internal/modules/cjs/loader.js:1078:30)

image