I have an app that should read serial input from a external scale and for that I made an electron app.
I tried searching for fix, but I could not find one suited for my needs or they don’t work…
I work on Linux, but app is for Windows OS, and interesting this is that I can build app through Linux but cannot on windows.
Error that I am encountering while trying build on windows OS:
C:UsersWinDesktop1.2.5>npm run build
> [email protected] build
> electron-builder --win
• electron-builder version=24.13.3 os=10.0.19045
• loaded configuration file=package.json ("build" field)
• @electron/rebuild not required if you use electron-builder, please consider to remove excess dependency from devDependencies
To ensure your native dependencies are always matched electron version, simply add script `"postinstall": "electron-builder install-app-deps" to your `package.json`
• writing effective config file=distbuilder-effective-config.yaml
• rebuilding native dependencies dependencies=@serialport/[email protected] platform=win32 arch=x64
⨯ cannot execute cause=exit status 1
errorOut=npm error code 1
npm error path C:UsersWinDesktop1.2.5node_modules@serialportbindings-cpp
npm error command failed
npm error command C:Windowssystem32cmd.exe /d /s /c node-gyp-build
npm error node:internal/child_process:421
npm error throw new ErrnoException(err, 'spawn');
npm error ^
npm error
npm error Error: spawn EINVAL
npm error at ChildProcess.spawn (node:internal/child_process:421:11)
npm error at Object.spawn (node:child_process:761:9)
npm error at build (C:UsersWinDesktop1.2.5node_modules@serialportbindings-cppnode_modulesnode-gyp-buildbin.js:29:8)
npm error at preinstall (C:UsersWinDesktop1.2.5node_modules@serialportbindings-cppnode_modulesnode-gyp-buildbin.js:38:32)
npm error at Object.<anonymous> (C:UsersWinDesktop1.2.5node_modules@serialportbindings-cppnode_modulesnode-gyp-buildbin.js:15:3)
npm error at Module._compile (node:internal/modules/cjs/loader:1546:14)
npm error at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
npm error at Module.load (node:internal/modules/cjs/loader:1317:32)
npm error at Module._load (node:internal/modules/cjs/loader:1127:12)
npm error at TracingChannel.traceSync (node:diagnostics_channel:315:14) {
npm error errno: -4071,
npm error code: 'EINVAL',
npm error syscall: 'spawn'
npm error }
npm error
npm error Node.js v22.6.0
npm error A complete log of this run can be found in: C:UsersWinAppDataLocalnpm-cache_logs2024-08-19T20_47_08_788Z-debug-0.log
command='C:Program Filesnodejsnode.exe' 'C:Program Filesnodejsnode_modulesnpmbinnpm-cli.js' rebuild @serialport/[email protected]
workingDir=
C:UsersWinDesktop1.2.5>
While building on Linux (success build, but app won’t start):
linux-mysistem:~/Desktop/Market App$ npm run build
> [email protected] build
> electron-builder --win
• electron-builder version=24.13.3 os=6.8.0-40-generic
• loaded configuration file=package.json ("build" field)
• @electron/rebuild not required if you use electron-builder, please consider to remove excess dependency from devDependencies
To ensure your native dependencies are always matched electron version, simply add script `"postinstall": "electron-builder install-app-deps" to your `package.json`
• writing effective config file=dist/builder-effective-config.yaml
• skipped dependencies rebuild reason=platform is different and buildDependenciesFromSource is set to true
• packaging platform=win32 arch=x64 electron=31.4.0 appOutDir=dist/win-unpacked
• building target=nsis file=dist/Market App Setup 1.2.5.exe archs=x64 oneClick=false perMachine=false
• building block map blockMapFile=dist/Market App Setup 1.2.5.exe.blockmap
Also, here is piece of my code that uses serialport: https://pastebin.com/raw/RJdJGwNu
Here is my package.json:
{
"name": "my-app",
"version": "1.2.5",
"description": "My app description",
"main": "main.js",
"scripts": {
"start": "electron main.js",
"dist": "electron-builder",
"build": "electron-builder --win",
"pack": "electron-builder --win --dir",
"postinstall": "electron-builder install-app-deps",
"rebuild": "electron-rebuild -f -w serialport"
},
"build": {
"appId": "com.name.app",
"productName": "My App",
"buildDependenciesFromSource": true,
"win": {
"icon": "assets/icon.png"
},
"nsis": {
"oneClick": false,
"allowToChangeInstallationDirectory": false,
"license": "assets/LICENSE.txt",
"installerIcon": "assets/icon-installer.ico",
"installerHeaderIcon": "assets/icon-installer.ico",
"uninstallerIcon": "assets/icon-uninstaller.ico",
"installerSidebar": "assets/sidebar.png",
"uninstallerSidebar": "assets/sidebar.png"
},
"files": [
"main.js",
"package.json",
"node_modules/**",
"scripts/**",
"pages/**",
"assets/**"
]
},
"devDependencies": {
"@types/electron-prompt": "^1.6.5",
"@types/fs-extra": "^11.0.4",
"@types/nedb": "^1.8.16",
"@types/node-schedule": "^2.1.7",
"electron": "^31.2.1",
"electron-builder": "^24.13.3",
"electron-rebuild": "^3.2.9"
},
"dependencies": {
"electron-prompt": "^1.7.0",
"fs-extra": "^11.1.1",
"nedb": "^1.8.0",
"node-schedule": "^2.1.1",
"serialport": "^12.0.0"
}
}