feat(plugin-vite): automatically switch to esm mode when enabled#4016
Open
maximsmol wants to merge 3 commits intoelectron:mainfrom
Open
feat(plugin-vite): automatically switch to esm mode when enabled#4016maximsmol wants to merge 3 commits intoelectron:mainfrom
maximsmol wants to merge 3 commits intoelectron:mainfrom
Conversation
87cce28 to
35082c7
Compare
Author
|
Could we move on this? Are there any blockers? |
BlackHole1
reviewed
Nov 20, 2025
Member
There was a problem hiding this comment.
What is the purpose of this file? Will the absence of this file cause test failures?
Author
There was a problem hiding this comment.
Yes. I could make it optional but IIRC there is some other code that actually relies on there always being a package.json anyway, except that it's not hit by the tests so the fixture worked before
Signed-off-by: maximsmol <1472826+maximsmol@users.noreply.github.com>
Signed-off-by: maximsmol <1472826+maximsmol@users.noreply.github.com>
Signed-off-by: maximsmol <1472826+maximsmol@users.noreply.github.com>
11adf77 to
19e674c
Compare
erickzhao
reviewed
Nov 25, 2025
Member
erickzhao
left a comment
There was a problem hiding this comment.
Hey @maximsmol, thanks for the PR. I recall having some offline discussion about this, and will get back with a review soon.
Please note that you have to get your commits signed for any contributions to Electron!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summarize your changes:
Electron now supports ESM by settings
"type": "module"inpackage.jsonbut@electron-forge/plugin-vitewill output CommonJS code regardless, which will then fail to load (typically by trying to referencerequire).This patch reads
typefrompackage.jsonand automatically changes the main vite config output format toesmif modules are requested. Note that we parsepackage.jsontwice now (the first time to look for a forge config) but this seemed cleaner than trying to pass the parsed JSON around.I am deliberately leaving preload scripts as-is since they ignore
"type": "module"and load fine with the current settings. That being said, Electron supports ESM preload scripts, so we might want to automatically change the output format there as well. This would also require renaming the output from.jsto.mjsThere is also the sandboxing limitation, which may mean that bundling to CommonJS is the best way for preload scripts regardless, but I do not understand well enough how people use preload scripts (and in particular how common sandboxing is) to make that decision.Please let me know if I need to add docs or automated tests here—the change is pretty trivial so I did not bother.
Related: #3684