Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Electron forge throws '.../python3.8" links out of the package' error when making with asar enabled on Mac

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:
{}
like image 264
Ricky Mo Avatar asked Oct 31 '25 19:10

Ricky Mo


1 Answers

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});
    }
  }
}
like image 145
Will Munn Avatar answered Nov 02 '25 09:11

Will Munn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!