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

Native module not working in development after universal macOS build #6260

Closed
guanxun14 opened this issue Sep 14, 2021 · 3 comments
Closed
Labels

Comments

@guanxun14
Copy link

guanxun14 commented Sep 14, 2021

  • Electron-Builder Version: 22.11.11
  • Node Version: 14.16.0
  • Electron Version: 13.1.5
  • Electron Type (current, beta, nightly): current
  • Target: macOS universal

1. Motivation

I'm just trying to understand what's going on here.

2. Background / The part that works

My electron app is using node-keytar [1], which is a native module. After installing with npm install keytar --save, running the app in development with my gulp && electron . command works fine.

Building with electron-builder (gulp && electron-builder) to produce a universal build also works fine, with the production app opening correctly on both m1 and intel (via Rosetta) arches. Relevant logs from building on m1 mac:

...
  • rebuilding native dependencies  dependencies=keytar@7.7.0 platform=darwin arch=x64
  • install prebuilt binary  name=keytar version=7.7.0 platform=darwin arch=x64 napi=
 • packaging       platform=darwin arch=x64 electron=13.1.5 appOutDir=dist/mac-universal--x64
  • rebuilding native dependencies  dependencies=keytar@7.7.0 platform=darwin arch=arm64
  • install prebuilt binary  name=keytar version=7.7.0 platform=darwin arch=arm64 napi=
 • packaging       platform=darwin arch=arm64 electron=13.1.5 appOutDir=dist/mac-universal--arm64
  • packaging       platform=darwin arch=universal electron=13.1.5 appOutDir=dist/mac-universal
...

[1] - Not sure if relevant, but node-keytar v7.7.0 (which is what I'm using) uses N-API prebuilds.

3. Issue / The part that breaks

The app however crashes when subsequently running in development again, the app window opens and errors out immediately as long as I have const keytar = require('keytar'); in my app. I've reliably replicated this locally. This is the error I get in devtools:

Uncaught Error: dlopen(/app_path/node_modules/keytar/build/Release/keytar.node, 1): no suitable image found.  Did find:
	/app_path/node_modules/keytar/build/Release/keytar.node: mach-o, but wrong architecture
	/app_path/node_modules/keytar/build/Release/keytar.node: mach-o, but wrong architecture
    at process.func [as dlopen] (electron/js2c/asar_bundle.js:5)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1138)
    at Object.func [as .node] (electron/js2c/asar_bundle.js:5)
    at Module.load (internal/modules/cjs/loader.js:935)
    at Module._load (internal/modules/cjs/loader.js:776)
    at Function.f._load (electron/js2c/asar_bundle.js:5)
    at Function.o._load (electron/js2c/renderer_init.js:33)
    at Module.require (internal/modules/cjs/loader.js:959)
    at require (internal/modules/cjs/helpers.js:88)
    at Object.<anonymous> (/app_path/node_modules/keytar/lib/keytar.js:1:169)

4. Findings / workaround

I've also found that re-installing keytar (with npm uninstall keytar, followed by npm install keytar --save) fixes the issue in development, and building for production thereafter continues to work and isn't adversely affected.

My uneducated, layman guess is that the build process is leaving keytar to use the arm64 arch prebuild after it's been built with electron-builder, as it comes after the x64 install prebuilt binary step. So when the app is run in development (which uses the x64 arch) again, it ends up not working.

5. Actual question

So as stated above, I'm just trying to find out if my guess is right, or am I misguided here? I would appreciate some clues and guidance, if possible. Suggestions for possible cleaner workflows regarding the workaround fix would certainly also be appreciated.

@quanglam2807
Copy link
Contributor

I haven’t checked this more carefully but this also affects production build. Universal package ends up using arm64 binary for both x64 and arm64

@stale
Copy link

stale bot commented Apr 17, 2022

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.

@stale stale bot added the backlog label Apr 17, 2022
@stale stale bot closed this as completed Apr 29, 2022
@rmartins90
Copy link

I'm having this same issue, but only when building in CI (GitHub Actions). Have you found a solution for this? I'm using electron-builder 23.6.0.

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

No branches or pull requests

3 participants