I'm playing around with Electron lately.
One of the things I wanted to do was build the Electron Application for Windows on my Linux development box, which runs Debian.
I used electron-builder for building the app.
In this post I'll focus on making electron-builder build the app for windows and will ignore setting up electron, electron-builder and making the electron app.
TL;DR
You need Wine 1.8+. Debian will install Wine 1.6.2.
To install Wine 1.8+ on Debian:
- Add Jessie Backports to /etc/apt/sources.list
- See: Installation from Jessie Backports
Configuration
To make electron-builder build for windows, the following is needed in package.json:
"build": {
"appId": "com.aaronlenoir.gnucash-reporter",
"win": {
"target": [
"zip"
]
}
},
For convenience, I have the following scripts too:
"scripts": {
...
"pack": "build --dir",
"dist": "build",
"pack-win": "build --dir --win",
"dist-win": "build --win"
},
That way, I can run npm run pack-win
to build for windows.
Building
Electron-builder needs Wine in order to build for windows. So I had installed it using apt:
apt-get install wine
Problem 1: Wine version
The first run, I got the following error:
$ npm run pack-win
> gnucash-reporter@0.0.1-alpha pack-win /home/user/electron/gnucash-reporter
> build --dir --win
Skip app dependencies rebuild because platform is different
TypeError: Invalid Version: it
at new SemVer (/home/user/electron/gnucash-reporter/node_modules/semver/semver.js:293:11)
at compare (/home/user/electron/gnucash-reporter/node_modules/semver/semver.js:566:10)
at lt (/home/user/electron/gnucash-reporter/node_modules/semver/semver.js:600:10)
at /home/user/electron/gnucash-reporter/node_modules/electron-builder/src/packager.ts:473:7
...
Note the strange message: TypeError: Invalid Version: it
Looking at the stack trace, it looked like it was checking the version of Wine. But apparently the version was not a valid Semver version number: "it".
The mystery was solved however, asking wine for its version:
$ wine --version
it looks like multiarch needs to be enabled. as root, please
execute "dpkg --add-architecture i386 && apt-get update &&
apt-get install wine32"
wine-1.6.2
Now it was clear where "it" came from. So I followed the instructions and ran:
dpkg --add-architecture i386 && apt-get update && apt-get install wine32
After that, wine had the following version:
$ wine --version
wine-1.6.2
So I ran npm run pack-win
again:
And received the error:
Error: wine 1.8+ is required, but your version is 1.6.2, please see https://github.com/electron-userland/electron-builder/wiki/Multi-Platform-Build#linux
Problem 2: Getting Wine 1.8
I'm not very familiar with debian, but I always assumed apt would give me the latest stable version of applications.
I followed the instructions on: https://github.com/electron-userland/electron-builder/wiki/Multi-Platform-Build#linux
But they don't work well on Debian, since it can't find the appropriate packages.
I found these instructions on the debian wiki, which worked:
- Add this line line to /etc/apt/sources.list
deb http://httpredir.debian.org/debian jessie-backports main
- Update the package lists
sudo apt-get update
- Then, for 64-bit systems:
sudo apt install \
wine/jessie-backports \
wine32/jessie-backports \
wine64/jessie-backports \
libwine/jessie-backports \
libwine:i386/jessie-backports \
fonts-wine/jessie-backports
After this:
$ wine --version
wine-1.8.6 (Debian 1.8.6-5~bpo8+1)
Results
After this the build succeeded:
user@debian:~/electron/gnucash-reporter$ npm run pack-win
> gnucash-reporter@0.0.1-alpha pack-win /home/user/electron/gnucash-reporter
> build --dir --win
Skip app dependencies rebuild because platform is different
Packaging for win32 x64 using electron 1.4.15 to dist/win-unpacked
user@debian:~/electron/gnucash-reporter$ ls
build dist install-builder-deps.sh LICENSE node_modules package.json README.md src test
user@debian:~/electron/gnucash-reporter$ cd dist/
user@debian:~/electron/gnucash-reporter/dist$ ls
linux-unpacked win-unpacked
win-unpacked, in windows, looks like this:
And running the executable ran the application without any issues.
.
Conclusion
You need:
- Electron
- Electron-Builder
- Wine 1.8+
Debian runs Wine 1.6.2 standard, and you need to add the "jessie backports" package source to your system in order to install Wine 1.8+.
For reference, the practice application I'm building in electron is on github: https://github.com/AaronLenoir/gnucash-reporter.