I am using electron 11.1.0 and electron-builder 22.10.5

I created a installer for my electron app which is using native module using electron-builder and its working fine on my laptop but on my friends laptop I am getting error

A JavaScript error occurred in the main process

Uncaught Exception:
Error: The specified module could not be found.
\\?C:\some\path\My-Electron-App\resources\app.asar.unpacked\node_modules\obs-studio-node\obs_studio_client.node

I have checked C:\some\path\My-Electron-App\resources\app.asar.unpacked\node_modules\obs-studio-node\obs_studio_client.node file exists.

I guess its asar related issue with native module. I tried by adding "asarUnpack": ["**/*.node"] in my build config but does not help.

How can I fix this problem?

2

There are 2 best solutions below

2
On

I could not get this working with asarUnpack. Instead I use

"asar": false

Increases the bundle size, but at least it works.

0
On

I had the same problem, with the same library. There are full details of the debugging steps here: https://github.com/aza547/wow-recorder/issues/328.

In summary:

  • Get the dependencies program (a modern dependency walker) and drop the .node file throwing the error in there to show what's not being found.
  • Note that node.exe is a false positive for obs-studio-node (it's a delay dependency) - not really sure what that is, but I can launch fine without it. I suspect it's only loaded in dev mode or something like that.
  • In my case (and probably yours as well) it was the Visual C++ Redistributable package from Microsoft, which is available here: https://aka.ms/vs/17/release/vc_redist.x64.exe
  • That's a common dependency of electron apps I believe. Streamlabs desktop (also using the same obs-studio-node library) installs it as as part of streamlabs desktop https://github.com/stream-labs/desktop/blob/master/installer.nsh.

I think lots of other apps will install this too, I had several copies on my machine when I went looking. That explains why some people never hit this and others do.

Removing them all, I could reproduce the issue. Then in Warcraft Recorder (my program) I fixed this in the same manner, here: https://github.com/aza547/wow-recorder/pull/379/files.

Effectively all that is doing is telling the NSIS installer to download that link and run it as part of the installation.

In package.json, add NSIS config and point it to a custom script:

"nsis": {
      "oneClick": false,
      "allowToChangeInstallationDirectory": true,
      "include": "installer.nsh",
      "deleteAppDataOnUninstall": true
    },

The installer.nsh file:

!macro customInstall
  NSISdl::download https://aka.ms/vs/17/release/vc_redist.x64.exe "$INSTDIR\vc_redist.x64.exe"  
  
  ${If} ${FileExists} `$INSTDIR\vc_redist.x64.exe`
    ExecWait '$INSTDIR\vc_redist.x64.exe /passive /norestart' $1

    ${If} $1 != '0' 
      ${If} $1 != '3010'
        MessageBox MB_OK|MB_ICONEXCLAMATION 'WARNING: Streamlabs was unable to install the latest Visual C++ Redistributable package from Microsoft.'
      ${EndIf}
    ${EndIf}

    # ${If} $1 == '3010'
    #     MessageBox MB_OK|MB_ICONEXCLAMATION 'You must restart your computer to complete the installation.'
    # ${EndIf}

  ${Else}
      MessageBox MB_OK|MB_ICONEXCLAMATION 'WARNING: Streamlabs was unable to download the latest Visual C++ Redistributable package from Microsoft.'
  ${EndIf}

  FileOpen $0 "$INSTDIR\installername" w
  FileWrite $0 $EXEFILE
  FileClose $0
!macroend