javascriptnode.jselectronelectron-packagerelectron-forge

Error whilst trying to package electron app


I am trying to package an electron app with the normal template (no frameworks). When I run: npm run package OR yarn run package. I get an error:

PS C:\GitHub\electron-project\lambda> yarn run package --platform win32
yarn run v1.22.22
$ electron-forge package --platform win32
✔ Checking your system
  › Determining targets...
  ❯ Packaging for x64 on win32
    ✔ Copying files
    ⠸ Preparing native dependencies
    ⠸ Finalizing package
◼ Running postPackage hook
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

My forge.config.js looks like this:

const { FusesPlugin } = require('@electron-forge/plugin-fuses');
const { FuseV1Options, FuseVersion } = require('@electron/fuses');

module.exports = {
  packagerConfig: {
    asar: true,
  },
  rebuildConfig: {},
  makers: [
    {
      name: '@electron-forge/maker-squirrel',
      config: {},
    },
    {
      name: '@electron-forge/maker-zip',
      platforms: ['darwin'],
    },
    {
      name: '@electron-forge/maker-deb',
      config: {},
    },
    {
      name: '@electron-forge/maker-rpm',
      config: {},
    },
  ],
  plugins: [
    {
      name: '@electron-forge/plugin-auto-unpack-natives',
      config: {},
    },
    // Fuses are used to enable/disable various Electron functionality
    // at package time, before code signing the application
    new FusesPlugin({
      version: FuseVersion.V1,
      [FuseV1Options.RunAsNode]: false,
      [FuseV1Options.EnableCookieEncryption]: true,
      [FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
      [FuseV1Options.EnableNodeCliInspectArguments]: false,
      [FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
      [FuseV1Options.OnlyLoadAppFromAsar]: true,
    }),
  ],
};

My packgage.json looks like:

{
  "name": "lambda",
  "productName": "lambda",
  "version": "alpha-1.0.0",
  "main": "src/index.js",
  "scripts": {
    "start": "electron-forge start",
    "package": "electron-forge package",
    "make": "electron-forge make",
    "publish": "electron-forge publish",
    "lint": "echo \"No linting configured\""
  },
  "devDependencies": {
    "@electron-forge/cli": "^7.4.0",
    "@electron-forge/maker-deb": "^7.4.0",
    "@electron-forge/maker-rpm": "^7.4.0",
    "@electron-forge/maker-squirrel": "^7.4.0",
    "@electron-forge/maker-zip": "^7.4.0",
    "@electron-forge/plugin-auto-unpack-natives": "^7.4.0",
    "@electron-forge/plugin-fuses": "^7.4.0",
    "@electron/fuses": "^1.8.0",
    "electron": "12.2.3",
    "tailwindcss": "^3.4.3"
  },
  "keywords": [],
  "author": "skyrxzz",
  "description": "something but not empty",
  "license": "MIT",
  "dependencies": {
    "electron-squirrel-startup": "^1.0.1",
    "gkm": "^0.2.0",
    "robotjs": "^0.6.0"
  }
}

Running on Node v16.14.0

I tried to package an electron app, expecting a package for win32, instead I got an error that told me nothing about the problem.


Solution

  • I debugged the index.js file using an npm package recommended by electron-forge support. It helped me identify that the issue was with robotjs. robotjs was paired with the wrong Node version ABI - 87 (Node.js v16.14.0) when it needed ABI - 93 (Node.js v16.0.0). To resolve this, I had to downgrade @electron-forge/cli to 6.0.0-beta.61 because the latest version at the time, 7.4.0, required Node.js v16.4.0 or later.