環境:
Linux CentOS8 x64
electron:27.1.0
electron-forge: 7.1.0
electron dev依賴包
"devDependencies": {
"@electron-forge/cli": "^7.1.0",
"@electron-forge/maker-deb": "^7.1.0",
"@electron-forge/maker-rpm": "^7.1.0",
"@electron-forge/maker-squirrel": "^7.1.0",
"@electron-forge/maker-zip": "^7.1.0",
"@electron-forge/plugin-auto-unpack-natives": "^7.1.0",
"@electron/rebuild": "^3.3.0",
"@vitejs/plugin-vue": "3.1.0",
"electron": "^27.1.0"
}
構建不同架構的軟件包
如果你想構建不同架構的軟件包,需要指定arch命令行參數。
命令:npm run make -- --arch="arm64,x64"
electron-forge cli關於arch參數的說明及使用方式
異常記錄
Cannot make for rpm, the following external binaries need to be installed: rpmbuild
An unhandled rejection has occurred inside Forge:
Error: Cannot make for rpm, the following external binaries need to be installed: rpmbuild
出現這個錯誤,代表你的系統上缺少環境依賴包,需要進行安裝。
安裝命令:dnf install rpm-build.x86_64
;有的異常給出的並不是包名,
而是命令,所以這個時候就需要查詢這個命令是在哪個包中再進行安裝。
也可以通過dnf search <包名>命令進行嘗試性的檢索,看看能不能找到。
libexec/platform-python3.6" links out of the package
An unhandled rejection has occurred inside Forge:
Error: /tmp/electron-packager/tmp-9UkTiG/resources/app/node_modules/@serialport/bindings-cpp/build/node_gyp_bins/python3: file "../../../../../usr/libexec/platform-python3.6" links out of the package
出現這個錯誤是一個bug,這裏需要修改forge.config.js文件或等同的配置項內容,添加hooks項。
修改後的文件內容如下:
const path = require('path')
const fs = require('node:fs/promises');
module.exports = {
packagerConfig: {
asar: true,
...
},
makers: [
...
],
plugins: [
...
],
hooks: {
packageAfterPrune: async (_config, buildPath) => {
const gypPath = path.join(
buildPath,
'node_modules',
'@serialport',
'bindings-cpp',
'build',
'node_gyp_bins'
);
await fs.rm(gypPath, {recursive: true, force: true});
}
}
};
注意:其他配置內容保留你自己的即可。
'@serialport','bindings-cpp'這裏是我這邊的模塊名稱,替換你自己的模塊命令。
導致這個錯誤的原因相關的文檔記錄:
node_gyp_bins導致下游包構建失敗
在 Mac 上啓用 asar 時,Electron forge 會拋出“.../python3.8”鏈接超出包”錯誤
Cannot make for deb, the following external binaries need to be installed: dpkg, fakeroot
An unhandled rejection has occurred inside Forge:
Error: Cannot make for deb, the following external binaries need to be installed: dpkg, fakeroot
at MakerDeb.ensureExternalBinariesExist
如果你構建deb格式的包,那麼可能就會出現上面這種錯誤,還是需要安裝這2個依賴包。
在安裝之前先執行
yum -y install epel-release
添加擴展倉庫包。
安裝命令:yum install dpkg-1.20.9-4.el8.x86_64
自己確認是否需要額外安裝的包:dpkg-devel.x86_64 dpkg-dev.noarch
fakeroot安裝命令:dnf install fakeroot.x86_64 fakeroot-libs.x86_64
Package name must start with an ASCII number or letter
Error: Package name must start with an ASCII number or letter
at DebianInstaller.sanitizeName
這裏是構建名稱的強制條件,我這邊沒有通過forge.config.js文件單獨配置名稱,所以我這裏修改的是package.json文件的內容。
"name": "test-exec-name",
You may need to re-bundle the app using Electron Packager's "executableName" option.
An unhandled rejection has occurred inside Forge:
Error: could not find the Electron app binary at "/path1/path2/...". You may need to re-bundle the app using Electron Packager's "executableName" option.
這裏也就是根據你提供的name名稱,並未找到二進制文件目錄,我這裏是使用package.json配置的name名稱,其他的配置文件會繼承這個屬性的值,所以,要不你就在marker配置項那裏單獨指定名稱,要不你就統一名稱,例如:name和productName名稱保持一致。
這是關於deb marker配置項:https://js.electronforge.io/interfaces/_electron_forge_maker_deb.InternalOptions.MakerDebConfigOptions.html
error: License field must be present in package: (main package)
這個錯誤很明確,就是你沒有聲明許可協議。在package.json包中添加"license": "GPL"即可,協議的值根據你自己的需要進行修改。