[Question] How to bundle for Windows on Mac
AdrianMrn opened this issue · comments
Sorry if questions aren't allowed here, please point me in the correct direction in that case.
keytar
version: 7.4.0
electron
version: 11.3.0
node
version: 14.15.4
I'm trying to build an Electron application with Webpack using node-loader
and electron-builder
. I'm working on a Mac, building for Mac, Windows and Linux.
The Mac production built started working when I added <key>com.apple.security.cs.disable-library-validation</key> <true/>
to my entitlements.plist file.
The Windows version is showing this error:
Uncaught Exception:
Error: node-loader:
Error:
C:\Users\…\….tmp.node is not a valid Win32 application.
…
I'm guessing this means the Webpack build on my Mac is not making use of the proper Windows prebuild version of Keytar, but I can't find any way to tell the process to use a different file for different platforms. Adding --win --ia32
to my electron-builder build
doesn't seem to do anything, maybe because this is too late in the build process?
I've also tried a couple of combinations of using electron-builder install-app-deps
, which doesn't change anything. I ran into mentions of rebuild
here: https://www.electron.build/multi-platform-build, which I don't 100% understand, but I think this is a step that is already handled in the build process of keytar
?
While building my application, electron-builder
does seem to use the prebuilt native modules from the GitHub releases:
• building target=macOS zip arch=x64 file=packages/Ray-1.13.0-mac.zip
• building target=DMG arch=x64 file=packages/Ray-1.13.0.dmg
• rebuilding native dependencies dependencies=keytar@7.4.0 platform=linux arch=x64
• install prebuilt binary name=keytar version=7.4.0 platform=linux arch=x64
• packaging platform=linux arch=x64 electron=11.3.0 appOutDir=packages/linux-unpacked
• Unpacking electron zip zipPath=undefined
• building target=snap arch=x64 file=packages/Ray_1.13.0_amd64.snap
• building target=AppImage arch=x64 file=packages/Ray-1.13.0.AppImage
• rebuilding native dependencies dependencies=keytar@7.4.0 platform=win32 arch=x64
I managed to fix the issue on Windows by using const keytar = require('keytar');
instead of an import
statement, which (I think) loads the module during runtime instead of buildtime, and thus bypasses webpack and node-loader.
This solution only seems to work for the Windows build though. The Linux version still throws an error:
A JavaScript error occurred in the main process
Uncaught Exception:
Error: node-loader:
Error: /tmp/.org.chromium.Chromium.MXMgGg: invalid ELF header
at Object.<anonymous> (/tmp/.mount_…/app.asar/dist/main.js:367:813)
…
If I build the application on Ubuntu for Linux, it works fine. But we'd really love to keep the entire build process on Mac, the app is not that big, and we'd rather not add yet another CI tool to our stack right now.
@AdrianMrn I don't use the library but I think you should be able to remedy this by adding node-keytar
to your externals
field in your Webpack config.
@Slapbox That's actually a good idea, I'll try that out when I'm doing some work on that project again. We ended up moving the entire build process to GitHub Actions after all.
@AdrianMrn would you mind sharing a good config / resource to build en electron app using GH Actions? Thanks :)
@julienma I based our config on Vercel's Hyper config, it works pretty well for us! https://github.com/vercel/hyper/blob/canary/.github/workflows/nodejs.yml
Thx @AdrianMrn!
Thank you @Slapbox, this was the only way I could get keytar working!!