Closed lkowalczyk87 closed 1 year ago
got the same :(
This appears to be an issue with the "automatic detection" logic mentioned in https://www.electron.build/generated/platformspecificbuildoptions by which I mean that the detection logic is behaving differently depending on the compiling platform rather than the target platform.
Running with debug enabled results in the following line appearing when building on Linux for Windows that doesnt exist for native Windows builds:
not packed into asar archive file=node_modules/@serialport/bindings-cpp/build/node_gyp_bins/python3 reason=contains executable code
Which is flagged by unpackDetector.ts
No such executable is being identified on a windows native build, so it doesn't strip the package out of the ASAR.
I've noticed that there are a couple of modules (e.g. ffprobe-static) that include an override to force unpacking, however in this case I don't think it is sensible to override and force packing on a per module basis. This is because based on what I've seen thus far I think this issue will occur with any Node-API modules using node-gyp-build, prebuildify etc
@develar & @mmaietta I noticed that you have authored a few of the changes to the unpack detector, so wonder if you could take a look or loop in someone who might be able to help?
We're kinda strapped in terms of maintainers
I think the best route may just be force unpacking python
, maybe it's failing at line isBinaryFileSync
not detecting python?
https://github.com/electron-userland/electron-builder/blob/8ae90611993c3b20fe2d30037ff3a68f9e5a8224/packages/app-builder-lib/src/asar/unpackDetector.ts#L82-L87
Can you try adding console.log("shouldUnpack", shouldUnpack, file, moduleName)
to line 88 and post the logs back of what comes up?
For the interim, would the below work? Or maybe a regex specific to @serialport
?
asarUnpack: '**\\*.{node,dll}',
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
Ok so I've dug a little deeper, and I don't think the asar packing/unpacking is actually the problem. The issue appears to be that on Linux despite electron-builder being told to target windows, the electron-rebuild process is recompiling the NAPI packages for Linux. I'm not sure why this is happening as there seems to be code in the packager specifically to avoid this (packager.ts#L522C1-L530)
If I completely disable the rebuild process then electron-builder on Linux successfully uses the prebuilt binaries and the cross build works correctly. This even works despite none of the asar being unpacked.
To do this I had to remove the script "postinstall": "electron-builder install-app-deps",
and configure the build with "buildDependenciesFromSource": false, "npmRebuild": false
@lkowalczyk87 & @zivlakmilos would you be able to check if those changes fix the cross build process for you?
@mmaietta thanks for your help, I'd be keen to get your thoughts on this workaround, as it seems like these config setting are the opposite of the current defaults, but 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.
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 ☹️
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
Thank you @mmaietta this is greatly appreciated!
Released 24.5.2 (electron-updater@6.1.3)
Hi, this still isn't working for me... Am I doing something wrong? :cry:
If you need any other info just ask that I can provide... really need to solve this
Are you able to set the environment variable to enable debug during the build? I wonder if the build process is failing for some reason...
You could also try forcing it to download the binaries instead per the "potential workarounds" I mentioned before to see if that works for you
I have tried the potential workaround, and this was the result:
And this is is the quite long output of electron-builder with the DEBUG="electron-builder" environment variable, strangely the install-app-deps command didn't output anything different with debug turned on...
The only errors that I could note on this output are the ones related to wine display requiring an X server that I cannot provide due to being in a CI environment.
Do you have mono and other build dependencies setup correctly too? (per https://www.electron.build/multi-platform-build.html#to-build-app-for-windows-on-linux)
Since you are seeing issues even when you force it to use the prebuild binaries, I think this is a problem with the cross build process itself (or missing dependencies) rather than with the compile of the native module.
I used the Docker section of this tutorial...
Could this warning be the reason of my problems? Everything worked fine till the serialport package was added
hmm, which image are you using? electronuserland/builder:wine-mono ?
I'm currently using image electronuserland/builder:wine
@GazHank, do you recommend switching over to electronuserland/builder:wine-mono? Could it work better?
It might be worth a try... if I try to cross build the electron-serialport example it requires mono, so your project might be the same
@GazHank Hello, I've finally tested changing my dockerfile to electronuserland/builder:wine-mono and updated serialport to v11, but still...
I'm starting to wonder if I could hire your help with this for any chance as this issue is needed to be solved in order to delivery a new feature for my company clients.
Thanks for all the help.
@Marlonzao do you know if this is purely a cross build issues? Does this work without issue if you build directly on a Windows machine (rather than via docker)?
@GazHank Building directly on a windows virtual machine raises this error:
@Marlonzao ok, so this looks to be a different problem compared to this initial issue. I think we might need more info about your project setup, or debug info from the build process. I've a feeling that the build process itself might throw out some warning signs if you enable debug during the builder process
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](https://github.com/electron-userland/electron-builder/assets/37898730/62713104-2d87-4a9e-a6e9-1a76225a8ad7)
[Windows] Resources folder![image](https://github.com/electron-userland/electron-builder/assets/37898730/1bbc234b-0645-4579-afcc-2ebee1f03e23)
[MacOS] Resources folder![image](https://github.com/electron-userland/electron-builder/assets/37898730/4c529197-4d87-4c9b-84e0-2e29087823cd)
Reproduction steps:
npm ci
npm run build-win