Electron-builder: javaScript error occurred in the main process

Created on 11 Mar 2020  路  12Comments  路  Source: electron-userland/electron-builder


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?

backlog

Most helpful comment

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.

All 12 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 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.

tried https://github.com/justadudewhohacks/opencv4nodejs/issues/493

by adding

"win": {
      "target": [
        "nsis",
        "msi"
      ],
      "extraResources": [
        {
          "from": "app/dist/redistributable/",
          "to": "../",
          "filter": "*"
        }
      ],
      "files": [
        "!node_modules/opencv-build/opencv/opencv/",
        "!node_modules/opencv-build/opencv/opencv_contrib/",
        "!node_modules/opencv-build/opencv/build/3rdparty/",
        "!node_modules/opencv-build/opencv/build/CMakeFiles/",
        "!node_modules/opencv-build/opencv/build/data/",
        "!node_modules/opencv-build/opencv/build/doc/",
        "!node_modules/opencv-build/opencv/build/downloads/",
        "!node_modules/opencv-build/opencv/build/etc/",
        "!node_modules/opencv-build/opencv/build/include/",
        "!node_modules/opencv-build/opencv/build/junk/",
        "!node_modules/opencv-build/opencv/build/lib/",
        "!node_modules/opencv-build/opencv/build/modules/",
        "!node_modules/opencv-build/opencv/build/opencv2/",
        "!node_modules/opencv-build/opencv/build/testdata/",
        "!node_modules/opencv-build/opencv/build/win-install/",
        "!node_modules/opencv-build/opencv/build/x64/",
        "!node_modules/opencv-build/opencv/build/bin/Debug/"
      ]
    },

without turn off asar

After observe the .node file, I wondered why there is no .node for opencv4node in the dist folder
image

After observe the .node file, I wondered why there is no .node for opencv4node in the dist folder
image

after added an opencv4nodejs.node to C:\Users\ben\Documents\GitHub\labmate\dist\win-unpacked\resources\app.asar.unpacked\node_modules\opencv-build\build\Release, it still not work

There is a file named ea8c35a5-7f2c-445f-b22c-1ff45cfa290d.tmp.node in the C:\Users\ben\AppData\Local\Temp

It seems some libs give the path wrong. ref error msg \\?\C:\Users\User\AppData\Local\Temp\b3ccaeda-cfb0-43e5-868c-cab1254fdf7d.tmp.node instead of C:\Users\User\AppData\Local\Temp\b3ccaeda-cfb0-43e5-868c-cab1254fdf7d.tmp.node

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 did it wrong bt appending that it outside the build

Still, I got a new error message.

Uncaught (in promise) Error: The specified module could not be found.
\\?\C:\Users\ben\AppData\Local\Programs\Labmate\resources\app.asar.unpacked\node_modules\opencv4nodejs\build\Release\opencv4nodejs.node
    at process.func (electron/js2c/asar.js:138:31)
    at process.func [as dlopen] (electron/js2c/asar.js:138:31)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:828:18)
    at Object.func (electron/js2c/asar.js:138:31)
    at Object.func [as .node] (electron/js2c/asar.js:147:18)
    at Module.load (internal/modules/cjs/loader.js:645:32)
    at Function.Module._load (internal/modules/cjs/loader.js:560:12)
    at Module.require (internal/modules/cjs/loader.js:685:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (C:\Users\ben\AppData\Local\Programs\Labmate\resources\app.asar\node_modules\opencv4nodejs\lib\cv.js:58:8)
    at Object.<anonymous> (C:\Users\ben\AppData\Local\Programs\Labmate\resources\app.asar\node_modules\opencv4nodejs\lib\cv.js:69:3)
    at Module._compile (internal/modules/cjs/loader.js:786:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
    at Module.load (internal/modules/cjs/loader.js:645:32)
    at Function.Module._load (internal/modules/cjs/loader.js:560:12)
    at Module.require (internal/modules/cjs/loader.js:685:19)

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

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.

Finalmente descubr铆 que este problema es causado por un m贸dulo de nodo nativo personalizado que hab铆a creado. Si un m贸dulo nativo no se carga por una mir铆ada de razones, se presentar谩 con:Error: The specified module could not be found.

En mi caso, faltaba una dependencia que requer铆a el m贸dulo de nodo nativo.

como lo solucionaste amigo? soy nuevo en esto

I did solve this my not using the native lib.

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ccorcos picture ccorcos  路  3Comments

xingoxu picture xingoxu  路  3Comments

StickNitro picture StickNitro  路  3Comments

omarkilani picture omarkilani  路  3Comments

philcockfield picture philcockfield  路  3Comments