electron-builder: Inconsistent build behavior regarding asar file

  • Electron-Builder Version: 23.6.0
  • Node Version: 18.13.0
  • Electron Version: 23.2.0
  • Electron Type (current, beta, nightly): current
  • Target: windows

Hi! I tried to prepare a distribution that targets Windows. When I run the build process on a Windows machine everything is fine and the app works perfectly, but when I run the build process on a MacOS app crashes during the start with the following error “A JavaScript error occurred in the main process”(screenshot below). What I noticed is that the resources folder differs between OSes. Any ideas about what have I missed?

Error image

[Windows] Resources folder image

[MacOS] Resources folder image

Reproduction steps:

  1. Clone https://github.com/lkowalczyk87/asar-issue-electron-build
  2. Run npm ci
  3. Run npm run build-win

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 7
  • Comments: 24

Most upvoted comments

Thanks @mmaietta 24.5.1 seems to fix the rebuild issue! it means I can drop the buildDependenciesFromSource and npmRebuild letting it recompile for the target platform 😃

I’ve avoided reintroducing the postinstall script as that doesnt seem to have changed, so am not sure it would be useful at this stage. Let me know if you would like me to test it…

Thank you for verifying!

It should work with the postinstall script, it’s running everything the same under the hood. That being said, I couldn’t have it distinguish between internal vs external modules since that was originally done by the app-builder-bin Go binary, so I couldn’t fetch the different modules to build. Now, electron/rebuild just handles everything

Okay, thanks for checking!

I wonder if this is just a result of the defaults and documentation being developed before we had NAPI and prebuildify; when it was expected that all native modules had to be rebuilt from source.

I have a strong hunch this is the case, it significantly predates me joining as a maintainer.

Can you try next v24.5.1? I reconfigured electron-builder to use the @electron/rebuild API directly as opposed to the entry point in https://github.com/electron-userland/electron-builder/pull/7629 so that it respects the destination platform instead of forcing process.platform

There are so many edge cases with native builds that it’s proving significantly difficult to capture all cases. The harder part is making sure that the unit test passes, but then there’s no way to test if the app actually runs ☹️

Hi @mmaietta thanks for your help. Here is a subset of the output from the console.log, the full output can be found in the attached file

shouldUnpack false /media/gaz/win10/Git/electron-serialport/node_modules/@serialport/bindings-cpp/dist/win32.js bindings-cpp
shouldUnpack true /media/gaz/win10/Git/electron-serialport/node_modules/@serialport/bindings-cpp/build/node_gyp_bins/python3 bindings-cpp
  • not packed into asar archive  file=node_modules/@serialport/bindings-cpp/build/node_gyp_bins/python3 reason=contains executable code
shouldUnpack false /media/gaz/win10/Git/electron-serialport/node_modules/@serialport/bindings-interface/CODE_OF_CONDUCT.md bindings-interface
shouldUnpack false /media/gaz/win10/Git/electron-serialport/node_modules/@serialport/bindings-interface/LICENSE bindings-interface

shouldUnpack.txt