Skip to content
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

Forge make combined with vite is creating an incomplete asar #3738

Open
3 tasks done
steveoh opened this issue Oct 17, 2024 · 8 comments
Open
3 tasks done

Forge make combined with vite is creating an incomplete asar #3738

steveoh opened this issue Oct 17, 2024 · 8 comments

Comments

@steveoh
Copy link

steveoh commented Oct 17, 2024

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.

Electron Forge version

7.5.0

Electron version

33.0.1

Operating system

windows 11

Last known working Electron Forge version

7.4.0

Expected behavior

npm run make creates an asar file that includes the node_modules and the app can run on windows successfully.

Actual behavior

node_modules aren't present and install fails with ERR_MODULE_NOT_FOUND

Steps to reproduce

  1. npm run make
  2. go to the out folder and find open the nupkg/resources/app.asar file
  3. run npx @electron/asar extract app.asar app
  4. notice there is no node_modules

Additional information

This is only happening on windows as I believe that is the only place that asar is used.
We are using vite instead of webpack.

Image

The main.js file from within the asar in the error message imports the following

import "node:path";
import "node:url";
import "electron";
import "electron-window-state";
import "update-electron-app";
import "./main-DWMHPuxT.js";
import "electron-squirrel-startup";
import "fs";
import "path";
import "url";
import "stream";
import "zlib";

Where electron-window-state and update-electron-app and I assume electron-squirrel-startup are not available to be imported.

@justgo97
Copy link

I'm not sure about 7.5.0 but in earlier versions it was needed to move electron-window-state and any other dependency that isn't getting bundled correctly to devDependencies in package.json, This is a known mismatch between vite and webpack in forge.

@steveoh
Copy link
Author

steveoh commented Oct 17, 2024

This works as expected downgrading to 7.4.0. I'll give this a try but no bundles are getting added to the app.asar file at 7.5.0.

Well now I'm getting a require is not defined error after making the project. :/

@XianZhengquan
Copy link

@steveoh I use electron-log and it works fine after downgrading.

@knice88
Copy link

knice88 commented Oct 29, 2024

I've had this happen to ubuntu as well, but found a way to get the trick:
When you run "npm run make" for the first time, open the @electron-forge/plugin-vite configuration, get the .vite/ folder, and delete the out/ folder; Then turn off the @electron-forge/plugin-vite config and run "npm run make" again to get a complete installer

@AimForNaN
Copy link

Ran into a similar issue with other packages. Found a work-around and modified it to work for me. Seems @electron/packager related.

// forge.config.js

const { spawn } = require('node:child_process');

module.exports = {
	hooks: {
		packageAfterPrune: async (config, build_path) => {
			const vite_config = await import('./vite.preload.config.mjs');
			const external = vite_config?.default?.build?.rollupOptions?.external || [];
			const commands = [
				'install',
				'--no-package-lock',
				'--no-save',
				...external,
			];

			return new Promise((resolve, reject) => {
				npm = spawn('npm', commands, {
					cwd: build_path,
					stdio: 'inherit',
					shell: true,
				});

				npm.on('close', (code) => {
					if (0 === code) {
						resolve();
						return;
					}

					reject(`Process exited with code: ${code}`);
				});

				npm.on('error', reject);
			});
		},
	},
	// ...
};

@hichemfantar
Copy link

hichemfantar commented Nov 3, 2024

same issue here, happens when trying to load a json file

const filePath = path.join(__dirname, "schedule.json");
const data = fs.readFileSync(filePath , "utf-8");

@hichemfantar
Copy link

hichemfantar commented Nov 3, 2024

temp workaround is to disable asar by modifying the following properties in forge.config.ts

const config: ForgeConfig = {
  packagerConfig: {
    asar: false,
  },
  plugins: [
    new FusesPlugin({
      [FuseV1Options.OnlyLoadAppFromAsar]: false,
    }),
  ],
};

@an78mK89fy
Copy link

This error is not related to ASAR. Even if ASAR is disabled, the error is still reported. I think it is a vite plug-in problem. It works normally in 7.4.0

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

8 participants