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: closed
- Created 3 years ago
- Reactions: 16
- Comments: 37 (5 by maintainers)
Commits related to this issue
- Fix desktop builds See https://github.com/electron/forge/issues/3506 — committed to badger-media/badger by markspolakovs 3 years ago
- yarn update for security fixes That led to this problem: https://github.com/electron/forge/issues/3506 and this problem: https://github.com/electron/forge/issues/3208 Fixing those led to changes in l... — committed to EmotionCognitionLab/factorial-design-breathing-study by noah10 3 years ago
- chore: bump up all non-major dependencies (#8314) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | Type | Update | |---|---|---|---|---|---|---|--... — committed to toeverything/AFFiNE by renovate[bot] 2 years ago
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.
It’s half a year later now. Meanwhile, electron-forge 7.4.0 was released and this problem still exists. Any update on how to migrate from electron-forge 7.2.0 to electron-forge 7.4.0 (vite+ts)?
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"@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.
@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!
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/forgeCan you provide a migration guide, to fix this issue?
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.
+1 !
@GitMurf Alright, I have a fix, but I hate it.
Note: I stripped out my app “dependencies” to just the externals, then I added
afterCopyto myforge.config.tspackagerConfig. I also removed therebuildConfig: {}because was rebuilding my project node_modules in situ. (not a problem until the nextnpm installbreaks the electron app because it’s depending on the project’s node modules for the native dependency).Strategy is to strip the copied package.json of devDependencies (and scripts, because we don’t need that developer data in the application anyway) and run npm install and electron/rebuild directly in the buildPath.
Here’s what I ended up with.
At least I’m popping the project’s
package-lock.jsonthere for some level of build sanity/consistency. I’m not sure if this is a heavy-weight solution (execSync) or not, (in the context of whatever else is running in forge).You might consider also adding …
… which is actually less code than installing AutoUnpackNatives (where I stole it from). My app seems to work either way (without asar, with asar, with asar+unpack).
In hindsight, it seems this is a general packager/forge issue and not specifically related to the vite-plugin, but in the ecosystem of all these pieces it’s hard to decide exactly which one of these is dropping the ball 🙃.
Good luck!
cc @erickzhao @caoxiemeihao @MarshallOfSound
I hate to post in an old gh issue, but the relevant conversation and starting point for a lot of the issues is described nicely in this discussion above. And I apologize for the
@pinging but feel it is necessary to understand where things sit in the new year as I am unclear and have tried to look through as many gh issues, PRs and docs as I can and have not been able to find an answer.Last year (during the time of the discussions above) after months of effort I got something working with v7.4 (had to do some git patches… see here: https://github.com/electron/forge/pull/3336#issuecomment-2076349319). And honestly after getting it working I did not want to touch anything again so I stopped following along. But we recently needed to update to Electron v34 and with that needed to update forge. So I updated to v7.6 and now am back to having my issues with native modules again. This time it is the fact that zero node_modules are being bundled with the
asareven though I mark them asexternalinvite.main.configas the forge docs currently state (see screenshot below).So my question is, what is the expectation for forge v7.6 and the vite plugin? Are external modules supposed to be packaged? Or do we have to handle this completely ourselves via a forge hook or something?
If there is a thread/discussion/post somewhere that already addresses this please point me there (and I apologize for not finding it) but I have spent several hours searching through old and new gh issues and PRs, the docs etc. and cannot figure out what the clear expectation is on how the vite plugin should be functioning for things like external deps (native node modules)?
Thanks!
You only see that there is an increase in template code for
v7.3.0, and you have overlooked what the approach ofv7.3.0brings and what incompatible aspects of Forge itself have been avoided.hot-restartandhot-reloadis very popular inelectron-viteandtauri, but implementing this feature in Forge without authorization can damage Forge’s own design. It’s simply impossible to advance.{"type": "module"}in thepackage. jsonof@electron-forge/plugin-vite, which is fatal for frameworks likesvelte, as Forge itself is built in the format ofCommonsJS(tsconfig. json) and cannot risk switching toESNextentirely due to thevite-template.BTW, if you feel that there is too much
@electron-forge/template-vitecode, it is recommended that you useelectron-vite(even without a separate config file, really simplify) or other frameworks.@GitMurf Okay, I did the thing.
forge-7.3.0-rewrite-esm-support:./vite.base.config.ts should be a shim that helps people migrate.
Copy-paste that file into the project, and then try taking whatever your existing configs are and wrap them with the appropriate
extendMainConfig(),extendPreloadConfig()orextendRendererConfig()wrappers. (these accept all 4 possible forms of configs, objects, functions, promises, and async functions, and will mix in what the vite.base.config and templates currently have).the only non-trivial (non
extendMainConfig({})andextendPreloadConfig({})) in this example isbecause svelte!
I’ve only tested this with
package.jsontype=module because svelte requires it. If anyone can do the legwork to validate this solution is stable in a commonjs/other-framework package, that would be great.Thanks for the nudge, I feel like I can finally update my actual project now!
@Ben-Avrahami @boldt this may be easier to apply for you.
EDIT: oof, it appears that I didn’t test preload. It seems to be imported by require in electron and therefore needs to be a
.cjsfile whenpackage.jsontype=module.Migrate to
7.3.0+vite.main.config.tsvite.renderer.config.tsvite.preload.config.tsDo 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