forge: Undocumented breaking change for Vite plugin in v7.3.0

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.3.0

Electron version

N/A

Operating system

All

Last known working Electron Forge version

7.2.0

Expected behavior

Upgrading your Vite plugin app from Electron Forge v7.2.0 to v7.3.0 is seamless.

Actual behavior

Changes in the build system during the upgrade to Vite 5 have produced an API-incompatible change, requiring users to upgrade.

Steps to reproduce

N/A

Additional information

To fix this issue, see the @electron-forge/template-vite template config files: https://github.com/electron/forge/tree/main/packages/template/vite/tmpl

About this issue

  • Original URL
  • State: open
  • Created 4 months ago
  • Reactions: 12
  • Comments: 31 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Chiming in here… I’ve been using configs based on modified 7.2.0 templates (vite + electron + svelte! 😉 ).

Upgrading to 7.3.0 causes my existing configs to … just not produce any output! (.vite/build/… empty: no main.js found).

I think I might be able to get things to work if I rebuild the changes in my templates on top of the new ones, but that seems involved for a minor release.

Note: I don’t think it’s the vite@5 update that’s causing my issue, as my package.json already specified "vite": "^5.2.6"

@caoxiemeihao I am fairly well versed in forge and vite but there is so much conversation here (and in other gh issues) about what needs to be patched where and what forge version and running migration scripts etc etc that I am confused and a bit lost.

Is it possible that you publish a minimal working template repo that has everything we need with forge 7.4 to work with forge-vite-typescript and ESM (type: module)? Basically what the vite typescript template should do (but it sounds like there are reasons why the template can’t work or something?).

I just think we need some “official” docs / direction that will also be maintained / supported by forge long term otherwise it will turn into a maintenance nightmare. Thanks!

Can you provide a migration guide, to fix this issue?

@GitMurf That is my understanding 👍 As @VerteDinde mentioned above we’re looking into options here, the issue is the breaking change is bidirectional. i.e. straight up reverting won’t help because then new apps will be broken in the opposite way to old apps. Right now you should pin to a version of forge that works for your app, and we’ll figure out how to make a way forward to higher forge versions.

Hey folks, sorry for our delay - we spoke about this in a maintainer meeting today. We’re deciding on a path forward, but wanted to briefly update the issue letting you know that there are currently eyes on this and we should be reporting back with fixes shortly.

Personally, the way this “migration” is being handled makes me want to run for the hills. I don’t think it is acceptable that an upgrade from 7.2 to 7.3 breaks my code, without any warning. The reason I am using something like forge in the first place is because I don’t want to look below the abstraction that covers all the messy details.

I’m a little concerned that this migration guide is implying the de-facto official path uses electron-forge-plugin-vite, which is maintained in a repo under @caoxiemeihao’s personal control.

Ideally any migration utility should be contributed and maintained under electron/forge

Personally, the way this “migration” is being handled makes me want to run for the hills. I don’t think it is acceptable that an upgrade from 7.2 to 7.3 breaks my code, without any warning. The reason I am using something like forge in the first place is because I don’t want to look below the abstraction that covers all the messy details.

You only see that there is an increase in template code for v7.3.0, and you have overlooked what the approach of v7.3.0 brings and what incompatible aspects of Forge itself have been avoided.

  1. The release speed of Vite is very fast, and Forge will not release a new version immediately due to a version update of Vite.
  2. The modern development experience of hot-restart and hot-reload is very popular in electron-vite and tauri, but implementing this feature in Forge without authorization can damage Forge’s own design. It’s simply impossible to advance.
  3. It is not possible to directly use {"type": "module"} in the package. json of @electron-forge/plugin-vite, which is fatal for frameworks like svelte, as Forge itself is built in the format of CommonsJS(tsconfig. json) and cannot risk switching to ESNext entirely due to the vite-template.
  4. Vite itself was not designed for Electron and does not even support Node.js construction. Forge exposes the configuration, which is beneficial for users to update the Vite version in a timely manner without waiting for Forge’s version update, and it can also more conveniently fix some unknown BUG.

BTW, if you feel that there is too much @electron-forge/template-vite code, it is recommended that you use electron-vite(even without a separate config file, really simplify) or other frameworks.

Migrate to 7.3.0+

Updated on 2024-04-25 (electron-forge-plugin-vite@0.6.1)


vite.main.config.ts

  import { defineConfig } from 'vite';
+ import { forgeViteConfig } from 'electron-forge-plugin-vite/migration';

  // https://vitejs.dev/config
- export default defineConfig({
+ export default defineConfig(forgeViteConfig.main({
    resolve: {
      // Some libs that can run in both Web and Node.js, such as `axios`, we need to tell Vite to build them in Node.js.
      browserField: false,
      conditions: ['node'],
      mainFields: ['module', 'jsnext:main', 'jsnext'],
    },
- });
+ }));

vite.renderer.config.ts

  import { defineConfig } from 'vite';
+ import { forgeViteConfig } from 'electron-forge-plugin-vite/migration';

  // https://vitejs.dev/config
- export default defineConfig({});
+ export default defineConfig(forgeViteConfig.renderer({}));

vite.preload.config.ts

  import { defineConfig } from 'vite';
+ import { forgeViteConfig } from 'electron-forge-plugin-vite/migration';

  // https://vitejs.dev/config
- export default defineConfig({});
+ export default defineConfig(forgeViteConfig.preload({}));

Can you provide a migration guide, to fix this issue?

+1 !

Do you mind pointing to the change that fixed the issue? There seems to be a lot going on there. Here’s my files: https://github.com/will-stone/browserosaurus