You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Undocumented breaking change for Vite plugin in v7.3.0 #3506
Reacted by Mirko Nasato, Fermin Coronel, rubenvara-cmz, rgander09, Zhang sile, Bill Kippe, viplifes, Anna Neiderud, Adi Dahiya, Robby Cornelissen and 6 more
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"
Reacted by Robby Cornelissen, Ben Avrahami, Théo Zahaf, GitMurf and Erwan d'Orgeville
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'],
},
- });+ }));
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)?
Reacted by Adi Dahiya, Aarón Negrín, Will Stone, Théo Zahaf, Eric Mun, Adrián Simón Reboredo and rtritto
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: #3336 (comment)). 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 asar even though I mark them as external in vite.main.config as 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)?
@GitMurf Okay, you sent me down the rabbit hole. The best I've found is that some of the forge VitePlugin methods are no longer actually run and copying dependencies was "removed" according to this comment.
Note: I stripped out my app "dependencies" to just the externals, then I added afterCopy to my forge.config.tspackagerConfig. I also removed the rebuildConfig: {} because was rebuilding my project node_modules in situ. (not a problem until the next npm install breaks 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.
At least I'm popping the project's package-lock.json there 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 ...
asar: {unpack: "**/{.**,**}/*.node",},
... 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 🙃.
Activity
phlegmaticprogrammer commentedon Mar 3, 2024
OmegaRogue commentedon Mar 3, 2024
will-stone commentedon Mar 20, 2024
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
sparecycles commentedon Mar 25, 2024
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"Ben-Avrahami commentedon Mar 28, 2024
sparecycles commentedon Mar 28, 2024
The only insight I didn't mention is that the main PR description ( #3468 ) admits
So, I think the expectation here is we recreate our build configs on the new base templates?
build(app): update vite config from electron-forge vite template
build(deps): upgrade electron-forge from 7.2.0 to 7.4.0 (#103)
boldt commentedon Apr 16, 2024
Can you provide a migration guide, to fix this issue?
Ben-Avrahami commentedon Apr 17, 2024
+1 !
Fix desktop builds
caoxiemeihao commentedon Apr 20, 2024
Migrate to
7.3.0+vite.main.config.tsimport { 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.tsimport { 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.tsimport { defineConfig } from 'vite'; + import { forgeViteConfig } from 'electron-forge-plugin-vite/migration'; // https://vitejs.dev/config - export default defineConfig({}); + export default defineConfig(forgeViteConfig.preload({}));23 remaining items
yarn update for security fixes
Migrate @electron-forge/plugin-vite to v7.4.0
Migrate @electron-forge/plugin-vite to v7.4.0 (#269)
boldt commentedon Aug 21, 2024
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)?
chore: bump up all non-major dependencies (#8314)
adidahiya commentedon Oct 7, 2024
Thanks for fixing this in #3583! I can finally upgrade electron-forge in my project 🙏🏽
GitMurf commentedon Jan 17, 2025
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: #3336 (comment)). 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!
sparecycles commentedon Jan 18, 2025
@GitMurf Okay, you sent me down the rabbit hole. The best I've found is that some of the forge VitePlugin methods are no longer actually run and copying dependencies was "removed" according to this comment.
#3632 (comment)
This turns out to be the cause of an instability issue I was having trouble chasing down, so I'm equally invested.
GitMurf commentedon Jan 18, 2025
Thank you for confirming I am not crazy :) hopefully the team will be able to point us to a workaround and we can work towards a long term solution.
sparecycles commentedon Jan 18, 2025
@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!