@electron-forge/plugin-auto-unpack-natives does not unpack natives
- Dominant language
- TypeScript
- Stars
- 7.1k
- Forks
- 641
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 30
Description
### Pre-flight checklist
- [x] I have read the [contribution documentation](https://github.com/electron/forge/blob/main/CONTRIBUTING.md) for this project.
- [x] I agree to follow the [code of conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project uses.
- [x] 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:
```bash
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`:
```diff
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:
```bash
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):
```ts
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:
```ts
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.
Contributor guide
Assessment
This issue has not been assessed yet.