Error “@serialport … is not Win32 application” when using electron-builder

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"
}
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật