autodetect js module type - only bundle esm#5515
Merged
Merged
Conversation
eb521d5 to
c0b51c1
Compare
This was referenced May 1, 2026
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.
This fixes a regression caused by the upgrade to esbuild.
Fixes #5512
Fixes #4440Fixes #3748Previously, the js bundling system would inline all imports by walking the js asset AST through swc, similar to, but not exactly how es modules work. When porting to esbuild, we specified esm as the output type, but not all inlined scripts can properly be outputted as es modules. Unfortunately, manganis didn't have any knobs to control this bundling behavior. Our one-size-fits-all approach led to bugs like #4450 which haven't had a good solution.
The real solution to this problem is to use es-module-lexer to determine the file type and only use esm if we detect esm-ism, cjs if the file ends in
.cjs, and then fall back to regular scripts. Unfortunately, there's no rust-based es-module-lexer package, so the fix required porting theirlexer.cfile to rust.https://github.com/guybedford/es-module-lexer/blob/main/src/lexer.c
We now act more like vite - we autodetect module type and then use the appropriate bundling system for each module. Manganis previously never defined exactly this behavior and our test suite didn't cover the wide breadth of js module types.
This PR targets the v0.7 branch - we can release an updated dioxus 0.7.7 with this fix backported. It will need to be ported to the new main as well.