Skip to content

Commit

Permalink
https://www.update.rocks/blog/fixing-the-python3/
Browse files Browse the repository at this point in the history
If you are using electron-packager or electron-forge, you might encounter the following error :

 An unhandled rejection has occurred inside Forge:
Error: /var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/electron-packager/darwin-x64/electron-example-darwin-x64-5AYzr2/Electron.app/Contents/Resources/app/node_modules/macos-alias/build/node_gyp_bins/python3: file "../../../../../../../../../../../../../Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11" links out of the package
This error is showing when trying to package an electron application for macOS with Electron Forge. It takes its root in electron-packager and is produced by node-gyp like described in this Github issue.

nodejs/node-gyp#2713
  • Loading branch information
obra committed Dec 19, 2023
1 parent 74e36e2 commit 11f0fe4
Showing 1 changed file with 55 additions and 19 deletions.
74 changes: 55 additions & 19 deletions forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { spawnSync } = require("child_process");
const { generateCLDRData } = require("./tools/precompile.js");
const { glob } = require('glob');
const fs = require('fs');
const path = require('path');

let config = {
packagerConfig: {
Expand Down Expand Up @@ -142,28 +143,63 @@ let config = {
}
return packageJson;
},
packageAfterPrune: async (forgeConfig, buildPath, electronVersion, platform, arch) => {
const npmInstall = spawnSync("npm", ["install", "--omit=dev"], {
cwd: buildPath,
stdio: "inherit",
shell: true,
});
packageAfterPrune: async (
forgeConfig,
buildPath,
electronVersion,
platform,
arch,
) => {
const npmInstall = spawnSync("npm", ["install", "--omit=dev"], {
cwd: buildPath,
stdio: "inherit",
shell: true,
});

// Clear out prebuilds for other architectures
// 1) we don't need them
// 2) windows binary signing tool blows up when it tries to sign them.

const prebuilds = glob.GlobSync(`${buildPath}/**/prebuilds/*`);
const matchString = new RegExp(`prebuilds/${platform}`);
prebuilds.found.forEach(function (path) {
if (!path.match(matchString)) {
fs.rmSync(path, { recursive: true });
}
});
// Workaround from https://www.update.rocks/blog/fixing-the-python3/
if (platform === "darwin") {
// Directory to inspect
const dirPath = path.join(
buildPath,
"node_modules/macos-alias/build/node_gyp_bins",
);
// Check if the directory exists
if (fs.existsSync(dirPath)) {
// List files in the directory
console.log("Contents of the directory before removal: ");
const files = fs.readdirSync(path.join(dirPath));
files.forEach((file) => {
console.log(file);
});

console.log(buildPath);
// Files to remove
const filesToRemove = ["python", "python2", "python3"];

// Clear out prebuilds for other architectures
// 1) we don't need them
// 2) windows binary signing tool blows up when it tries to sign them.

const prebuilds = glob.GlobSync(`${buildPath}/**/prebuilds/*`);
const matchString = new RegExp(`prebuilds/${platform}`);
prebuilds.found.forEach(function(path) {
if (! path.match(matchString)) {
fs.rmdirSync(path, { recursive: true });
}
});
// Remove files if they exist
filesToRemove.forEach((file) => {
const filePath = path.join(dirPath, file);
if (fs.existsSync(filePath)) {
console.log(`Removing file: ${file}`);
fs.unlinkSync(filePath);
}
});
} else {
console.log(`Directory not found: ${dirPath}`);
}
}
},
},
}
};
if (process.env.UNTRUSTED) {
delete config['packagerConfig']['osxSign'];
Expand Down

0 comments on commit 11f0fe4

Please sign in to comment.