Skip to content

@electron-forge/plugin-auto-unpack-natives does not unpack natives #3934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
kuroshio opened this issue May 8, 2025 · 6 comments
Open
3 tasks done

@electron-forge/plugin-auto-unpack-natives does not unpack natives #3934

kuroshio opened this issue May 8, 2025 · 6 comments

Comments

@kuroshio
Copy link

kuroshio commented May 8, 2025

Pre-flight checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project uses.
  • I have searched the issue tracker for a bug that matches the one I want to file, without success.

Forge version

7.8.0

Electron version

v36.2.0

Operating system

Windows 10 (19045)

Last known working Forge version

7.3.1

Expected behavior

When creating a new project and installing a native dependency, the native node binding should be available in the resources/app.asar.unpacked directory.

Actual behavior

The app.asar.unpack folder does not exist, the native bindings are not in the app.asar either.

Steps to reproduce

Create a new project using the Vite + Typescript template:

npx create-electron-app@latest vite_electron_natives --template=vite-typescript
cd vite_electron_natives

Ensure that AutoUnpackNatives plugins is included in the forge.config.ts:

  import { FuseV1Options, FuseVersion } from '@electron/fuses';
+ import { AutoUnpackNativesPlugin } from '@electron-forge/plugin-auto-unpack-natives';

  const config: ForgeConfig = {
...
    plugins: [
+     new AutoUnpackNativesPlugin({}),
      new VitePlugin({

Install any native plugin and package:

npm install better-sqlite3
npm run package

Additional information

I have spent hours trying to get this to work. The only way I have been able to make it work is by using the following packagerConfig in forge.config.ts (along with the AutoUnpackNatives plugin):

  packagerConfig: {
    asar: true,
    prune: true,
    ignore: (file: string) => {
      if (!file) return false;
      const keep = file.startsWith('/.vite') || (file.startsWith('/node_modules'));
      return !keep;
    }
  },

I also tried adding the vite-plugin-native plugin, which had no effect.

I have an electron-forge + Vite project using Electron Forge version 7.3.1 which works perfectly fine with the following configuration:

const config: ForgeConfig = {
  packagerConfig: {
    asar: true,
    prune: true,
  },
  rebuildConfig: {
    force: true,
  },
  makers: [new MakerSquirrel({}), new MakerZIP({}, ['darwin']), new MakerRpm({}), new MakerDeb({})],
  plugins: [
    new AutoUnpackNativesPlugin({}),
    new VitePlugin({
      // `build` can specify multiple entry builds, which can be Main process, Preload scripts, Worker process, etc.
      // If you are familiar with Vite configuration, it will look really familiar.
      build: [
        {
          // `entry` is just an alias for `build.lib.entry` in the corresponding file of `config`.
          entry: 'src/main/main.ts',
          config: 'vite.main.config.ts',
        },
        {
          entry: 'src/preload/preload.ts',
          config: 'vite.preload.config.ts',
        },
      ],
      renderer: [
        {
          name: 'main_window',
          config: 'vite.renderer.config.ts',
        },
      ],
    }),
    // 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,
    }),
  ],
};

export default config;

It no longer works after upgrading to any version above 7.3.1. Just bumping the version to 7.4.0 causes the native modules to stop being unpacked.

Please let me know if you have any suggestions as I would love to upgrade to the latest version of Electron Forge.

@DAVIAMERICO242
Copy link

Your issue saved me from hours of debugging. It's still not solved on 7.8.1 regarless thank you.

@ferminc
Copy link

ferminc commented May 11, 2025

I currently have it working on [email protected] with

plugins: [
    {
      name: '@electron-forge/plugin-auto-unpack-natives',
      config: {}
    }
  ]

but you need to add some code in your forge config to package external deps, see #3738 (comment)

@DAVIAMERICO242
Copy link

Im getting a lot of pain head with prisma, mikroORM all of it's getting me some problem on electron forge. I cant debug render in vscode etc. I think im gonna switch to electron-vite only. I feel it's coded thinking I'll just do a web site and embed it on electron without any native stuff as usb sqlite etc

@tclxsr
Copy link

tclxsr commented May 21, 2025

Try use WEBPACK instead of vite.

@nilkanth987
Copy link

Im getting a lot of pain head with prisma, mikroORM all of it's getting me some problem on electron forge. I cant debug render in vscode etc. I think im gonna switch to electron-vite only. I feel it's coded thinking I'll just do a web site and embed it on electron without any native stuff as usb sqlite etc

Does electron-vite fixes the issue? I think it uses forge for distribution. Let me know if it works. I am facing the same issue.

@DAVIAMERICO242
Copy link

Im getting a lot of pain head with prisma, mikroORM all of it's getting me some problem on electron forge. I cant debug render in vscode etc. I think im gonna switch to electron-vite only. I feel it's coded thinking I'll just do a web site and embed it on electron without any native stuff as usb sqlite etc

Does electron-vite fixes the issue? I think it uses forge for distribution. Let me know if it works. I am facing the same issue.

I fixed the most of problems regarding native libs but still not able to run prisma/mikro it was getting too hard ... for me it means prisma/mikro was not made to electron even I get a way to make it working at a first time. I switched to drizzle and not painhead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants