79771865

Date: 2025-09-22 16:57:36
Score: 0.5
Natty:
Report link

Based on the solution from HellNoki, I encountered a library with a somewhat deep dependency tree. I had to opt for an alternative solution, letting npm do its job...,

import type { ForgeConfig } from "@electron-forge/shared-types";
import { execSync } from "child_process";

const config: ForgeConfig = {
    packagerConfig: {
        asar: true,
    },
    rebuildConfig: {},
    hooks: {
        // The call to this hook is mandatory for exceljs to work once the app built
        packageAfterCopy(_forgeConfig, buildPath) {
            const requiredNativePackages = ["[email protected]"]; // or "exceljs"

            // install all asked packages in /node_modules directory inside the asar archive
            requiredNativePackages.map((packageName) => {
                execSync(`npm install ${packageName} -g --prefix ${buildPath}`);
            });
        },
    },
    // ... others configs
    
};

export default config;

That way, even if the library has new dependencies in the future, there won't be any breakage.

However, remember to update the package version if it is modified.

npm install packageName -g --prefix 'directory' allows you to install a package in a node_modules folder other than the current directory. As seen here https://stackoverflow.com/a/14867050/21533924

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Alexandre