I am trying to distribute an electron project. So I follow the official guide and use electron-forge. Here is my config.forge:
"config": {
"forge": {
"packagerConfig": {
"asar":true,
"ignore":[
"^/[.].+$",
"^/app/src$",
"^.*/tsconfig([.].*)?[.]json",
"^/angular[.]json",
"^/frontend$",
"^/build$"
]
},
"makers": [
{
"name": "@electron-forge/maker-squirrel",
"config": {
"name": "my-app"
}
},
{
"name": "@electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "@electron-forge/maker-deb",
"config": {}
},
{
"name": "@electron-forge/maker-rpm",
"config": {}
}
]
}
}
It builds fine without asar:true. But if I add asar:true, it throws this error:
An unhandled rejection has occurred inside Forge:
Error: /var/folders/k1/12r0xrxd01n7zgfpqfxppqm80000gn/T/electron-packager/darwin-arm64/my-app-darwin-arm64/Electron.app/Contents/Resources/app/node_modules/@serialport/bindings-cpp/build/node_gyp_bins/python3: file "../../../../../../../../../../../../../Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/bin/python3.8" links out of the package
Electron Forge was terminated. Location:
{}
A fix for this has been recently merged in node-gyp. While we wait for this to be upgraded there is a workaround, if you're using electron forge, you can remove the node_gyp_bins directory in a hook in your electron forge config. Something like this worked for me (replacing module name with the offending module).
const path = require('path')
const fs = require('node:fs/promises');
{
....
hooks: {
packageAfterPrune: async (_config, buildPath) => {
const gypPath = path.join(
buildPath,
'node_modules',
'moduleName',
'build',
'node_gyp_bins'
);
await fs.rm(gypPath, {recursive: true, force: true});
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With