Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'installing native dependencies' dependency not included for all platforms #8528

Closed
dancarasco opened this issue Sep 24, 2024 · 6 comments · Fixed by #8537
Closed

'installing native dependencies' dependency not included for all platforms #8528

dancarasco opened this issue Sep 24, 2024 · 6 comments · Fixed by #8537

Comments

@dancarasco
Copy link

dancarasco commented Sep 24, 2024

  • Electron-Builder Version: 25.0.5
  • Node Version: 20.16.0
  • Electron Version: 32.1.2
  • Electron Type (current, beta, nightly): current
  • Target: Mac (dmg/universal+zip) + Win (x64 nsis)

I am on an M2 Max Macbook Pro building for universal mac + windows. When running electron-builder --mac --win on electron-builder 25.0.5, 'installing native dependencies' results in a missing native dependency (sqlite3) for the windows build:

  • electron-builder  version=25.0.5 os=23.6.0
  • loaded configuration  file=/Users/dan/Projects/TestApp/electron-builder.yml
  • writing effective config  file=dist/builder-effective-config.yaml
  • executing @electron/rebuild  electronVersion=32.1.2 arch=x64 buildFromSource=false appDir=./
  • installing native dependencies  arch=x64
  • preparing       moduleName=sqlite3 arch=x64
  • finished        moduleName=sqlite3 arch=x64
  • completed installing native dependencies
  • packaging       platform=darwin arch=x64 electron=32.1.2 appOutDir=dist/mac-universal-x64-temp
  • executing @electron/rebuild  electronVersion=32.1.2 arch=arm64 buildFromSource=false appDir=./
  • installing native dependencies  arch=arm64
  • preparing       moduleName=sqlite3 arch=arm64
  • finished        moduleName=sqlite3 arch=arm64
  • completed installing native dependencies
  • packaging       platform=darwin arch=arm64 electron=32.1.2 appOutDir=dist/mac-universal-arm64-temp
  • packaging       platform=darwin arch=universal electron=32.1.2 appOutDir=dist/mac-universal
  • signing         file=dist/mac-universal/TestApp.app platform=darwin type=distribution identity=hidden provisioningProfile=none
  • notarization successful
  • building        target=DMG arch=universal file=dist/TestApp-Mac-1.1.10-Installer.dmg
  • building        target=macOS zip arch=universal file=dist/TestApp-Mac-1.1.10-Installer.zip
  • executing @electron/rebuild  electronVersion=32.1.2 arch=x64 buildFromSource=false appDir=./
  • installing native dependencies  arch=x64
  • Detected arm64 process, HFS+ is unavailable. Creating dmg with APFS - supports Mac OSX 10.12+
  • preparing       moduleName=sqlite3 arch=x64
  • finished        moduleName=sqlite3 arch=x64
  • completed installing native dependencies
  • packaging       platform=win32 arch=x64 electron=32.1.2 appOutDir=dist/win-unpacked
  • updating asar integrity executable resource  executablePath=/Users/dan/Projects/TestApp/dist/win-unpacked/TestApp.exe
  • building block map  blockMapFile=dist/TestApp-Mac-1.1.10-Installer.dmg.blockmap
  • building block map  blockMapFile=dist/TestApp-Mac-1.1.10-Installer.zip.blockmap
  • building        target=nsis file=dist/TestApp-Windows-1.1.10-Setup.exe archs=x64 oneClick=true perMachine=true
  • building block map  blockMapFile=dist/TestApp-Windows-1.1.10-Setup.exe.blockmap

The app launches fine on Mac, but fails with a javascript 'cannot find module' error on Windows. When downgrading to electron-builder 24.13.3 'rebuilding native dependencies' is successfully called for the windows build and the app launches successfully on both platforms:

  • electron-builder  version=24.13.3 os=23.6.0
• loaded configuration  file=/Users/dan/Projects/TestApp/electron-builder.yml
• writing effective config  file=dist/builder-effective-config.yaml
• rebuilding native dependencies  [email protected] platform=darwin arch=x64
• packaging       platform=darwin arch=x64 electron=32.1.2 appOutDir=dist/mac-universal-x64-temp
• rebuilding native dependencies  [email protected] platform=darwin arch=arm64
• packaging       platform=darwin arch=arm64 electron=32.1.2 appOutDir=dist/mac-universal-arm64-temp
• packaging       platform=darwin arch=universal electron=32.1.2 appOutDir=dist/mac-universal
• signing         file=dist/mac-universal/TestApp.app platform=darwin type=distribution identity=hidden provisioningProfile=none
• notarization successful
• building        target=DMG arch=universal file=dist/TestApp-Mac-1.1.10-Installer.dmg
• building        target=macOS zip arch=universal file=dist/TestApp-Mac-1.1.10-Installer.zip
• Detected arm64 process, HFS+ is unavailable. Creating dmg with APFS - supports Mac OSX 10.12+
• rebuilding native dependencies  [email protected] platform=win32 arch=x64
• packaging       platform=win32 arch=x64 electron=32.1.2 appOutDir=dist/win-unpacked
• building block map  blockMapFile=dist/TestApp-Mac-1.1.10-Installer.dmg.blockmap

The 25.0.5 build results in a "Cannot find module" javascript error upon app launch on Windows. I am using unpacked version of sqlite3 which requires the native rebuilds. I was struggling to follow the logs from 25.0.5, am unsure whether it isn't building the win x64 module at all, or failing to copy it in at the correct time, as I can see it did an rebuild for x64 but the app cannot launch as it can't find the rebuilt dependency on Windows.

Additionally, the uncaught exception on Windows specifically targets a cannot find module error via a missing file to 'resources\app.asar\node_modules\sqlite3....' even though I've configured this to be unpacked.

Simply rolling electron-builder back to 24.13.3 and running the same build again without any changes results in a successfully built app that can launch with the native dependency on all platforms.

asarUnpack:
- node_modules/sqlite3
mac:
target:
  - target: "dmg"
    arch:
      - "universal"
  - target: "zip"
    arch:
      - "universal"
win:
target:
  - target: "nsis"
    arch:
      - "x64"
npmRebuild: true
@dancarasco dancarasco changed the title 'installing native dependencies' not running for all platforms 'installing native dependencies' dependency not included for all platforms Sep 24, 2024
@mmaietta
Copy link
Collaborator

Could you share a sample package.json that I could use to setup a test project locally with?

@dancarasco
Copy link
Author

Could you share a sample package.json that I could use to setup a test project locally with?

Minimal reproduction repo here https:/dancarasco/electron-builder-8528

After "npm run build" you should have a universal mac and x64 windows build. The mac app launches successfully on mac, but on Windows, the installer runs fine and then launching the app results in:

Screenshot 2024-09-24 163905

@mmaietta
Copy link
Collaborator

mmaietta commented Sep 24, 2024

Thank you! This is quite odd indeed, it seems that the windows .node binaries do not exist at all.

Expected path: electron-builder-8528\dist\win-unpacked\resources\app.asar\node_modules\sqlite3\lib\binding\napi-v6-win32-unknown-x64\node_sqlite3.node
That win32 folder doesn't exist, only modules for darwin .node binaries.

Seems to happen with both nativeRebuilder: legacy and sequential modes, so I'm thinking it's something within electron-builder logic and not electron-rebuild. I'll keep diving deeper

UPDATE: @dancarasco can you try with v25.1.5 with nativeRebuilder: "legacy", I'm able to run the app with it producing the proper dependencies. This should unblock you for now while being update to latest electron-builder. I'll continue investigating, but it's seeming like it may be a limitation with electron-rebuild package. Can't confirm just yet

Quick side note: You can test without installing the app by just running the exe from within win-unpacked

@mmaietta
Copy link
Collaborator

Found the origin of the issue. Basically, electron-rebuild has a hardcoded process.platform for --target_platform entry for node-pre-gyp, which is why we keep downloading darwin prebuilds instead

Opened a PR for electron-rebuild electron/rebuild#1153

mmaietta added a commit that referenced this issue Oct 1, 2024
Updates to latest electron-rebuild that allows passing in `platform` for
prebuilt node modules (previous versions of electron-rebuild had
hardcoded `process.platform`)

Fixes: #8528
#8426
xyloflake pushed a commit to xyloflake/electron-builder that referenced this issue Oct 2, 2024
Updates to latest electron-rebuild that allows passing in `platform` for
prebuilt node modules (previous versions of electron-rebuild had
hardcoded `process.platform`)

Fixes: electron-userland#8528
electron-userland#8426
@mmaietta
Copy link
Collaborator

mmaietta commented Oct 2, 2024

Released in 25.1.7, please feel free to give it a shot!

@dancarasco
Copy link
Author

Released in 25.1.7, please feel free to give it a shot!

Brilliant, thank you for tackling this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants