electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.66k stars 1.74k forks source link

Native Dependencies missing in electron-builder 24 #7621

Closed MuhKuh7 closed 1 year ago

MuhKuh7 commented 1 year ago

I am building for Windows on a Linux machine. With electron-builder 23 that works fine and I can see that the native dependencies (keytar in my case) are handled.

> electron-builder install-app-deps

  • electron-builder  version=23.6.0
  • loaded configuration  file=package.json ("build" field)
  • loaded parent configuration  preset=react-cra
  • rebuilding native dependencies  dependencies=keytar@7.9.0, register-scheme@0.0.2 platform=win32 arch=x64
  • install prebuilt binary  name=keytar version=7.9.0 platform=win32 arch=x64 napi=

But when I update to version 24, the application built on Linux does not run on Windows anymore and throws a "not a win32 application" error. When built on Windows it works. From the output I noticed that there is no mention anymore of the native dependencies.

> electron-builder install-app-deps

  • electron-builder  version=24.4.0
  • loaded configuration  file=package.json ("build" field)
  • loaded parent configuration  preset=react-cra
  • executing @electron/rebuild  arch=x64 version=25.1.1 appDir=/opt/work/93594e21797f15d9/app
mmaietta commented 1 year ago

We had to transition to the official electron/rebuild package due to newer Electron versions requiring additional compiler flags. I'm wondering if you're running into this issue https://github.com/electron-userland/electron-builder/pull/7465

Can you create a sample repo to reproduce this? I can investigate on it locally.

mmaietta commented 1 year ago

Can you please try release 24.5.1 and report back if that resolves your issue?

MuhKuh7 commented 1 year ago

Can you please try release 24.5.1 and report back if that resolves your issue?

Unfortunately still the same with version 24.5.1

s00d commented 1 year ago

Can you please try release 24.5.1 and report back if that resolves your issue?

Unfortunately still the same with version 24.5.1

try 24.5.1 and npmRebuild: true, it's help me

MuhKuh7 commented 1 year ago

try 24.5.1 and npmRebuild: true, it's help me

doesn't do anything for me

mmaietta commented 1 year ago

Can you please try 24.6.1? 🤞

MuhKuh7 commented 1 year ago

Now the build fails ;)

> electron-builder install-app-deps

  • electron-builder  version=24.6.1
  • loaded configuration  file=package.json ("build" field)
  • loaded parent configuration  preset=react-cra
  ⨯ Cannot read properties of undefined (reading 'value')  failedTask=installAppDeps stackTrace=TypeError: Cannot read properties of undefined (reading 'value')
    at rebuild (/app/node_modules/app-builder-lib/src/util/yarn.ts:169:49)
    at installOrRebuild (/app/node_modules/app-builder-lib/src/util/yarn.ts:29:11)
    at installAppDeps (/app/node_modules/electron-builder/src/cli/install-app-deps.ts:58:3)
mmaietta commented 1 year ago

On it! Will attempt to take a look tonight

mmaietta commented 1 year ago

Try 24.6.2 🙂

MuhKuh7 commented 1 year ago

Try 24.6.2 🙂

Seems to work now. Only strange thing is that it reports the platform used as "linux" which is the system it is built on instead of "win32" which it is built for. Since the built application runs under Windows I assume it actually used the correct binaries though.

> electron-builder install-app-deps

  • electron-builder  version=24.6.2
  • loaded configuration  file=package.json ("build" field)
  • loaded parent configuration  preset=react-cra
  • rebuilding native dependencies  dependencies=keytar@7.9.0 platform=linux arch=x64
  • install prebuilt binary  name=keytar version=7.9.0 platform=linux arch=x64 napi=
mmaietta commented 1 year ago

I think prebuild installs all OS version? Not sure.

Can this issue be closed?

universal commented 1 year ago

I am running into a similar issue trying to cross-build from linux to windows. I have tried finding the problem on and off for quite a while now, but can't figure it out. The problem might very well be the package with a native dependency I use (https://www.npmjs.com/package/@tauubyebye/win-audio).

I just created a very minimal electron app that exhibits the problem: https://github.com/universal/electron-native-dependencies-cross-build

I am still getting familiar with the whole electron/js-ecosystem and have so far no real clue about how native dependencies work. If the problem is in the used package, a pointer to how to fix it there would be very much appreciated.

I also tried building the app through the docker images and based the command in build.sh off of your example for travis.

If i can help in any way in debugging this I am happy to do/provide whatever you need :-) Your help is very much appreciated.

A little bit further reading indicates that cross-compiling of native dependencies in a package does not really work (as far as i understood it). What should work if precompiled binaries are uploaded to github. The package I use does not have those. I am now trying to figure out how and where to put those.

mmaietta commented 1 year ago

What should work if precompiled binaries are uploaded to github. The package I use does not have those.

If the package does not have those, then you need to compile the dependencies from the source code, meaning you need a Mac and a Windows build node at minimum. (Mac build node can compile Linux .node modules) Cross-compiling native dependencies is not possible.

universal commented 1 year ago

thanks for your reply :-) that is what i figured as well. figuring out prebuild/prebuildify now... :-)

universal commented 1 year ago

finally found something that works. could not get prebuildify to work, but something based on prebuild / prebuild-install appears to be working now :-) hopefully i can now ditch the vms with windows. The forked library is at https://github.com/universal/win-audio if you are looking for some inspiration... haven't added any ci-pipelines here.

so this works for me with 24.6.3 :-)