Skip to content

autodetect js module type - only bundle esm#5515

Merged
jkelleyrtp merged 9 commits into
v0.7from
jk/regression-fix
May 1, 2026
Merged

autodetect js module type - only bundle esm#5515
jkelleyrtp merged 9 commits into
v0.7from
jk/regression-fix

Conversation

@jkelleyrtp
Copy link
Copy Markdown
Member

@jkelleyrtp jkelleyrtp commented Apr 28, 2026

This fixes a regression caused by the upgrade to esbuild.

Fixes #5512
Fixes #4440
Fixes #3748

Previously, 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 their lexer.c file 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.

@jkelleyrtp jkelleyrtp requested a review from a team as a code owner April 28, 2026 23:07
@jkelleyrtp jkelleyrtp changed the base branch from main to v0.7 April 28, 2026 23:09
@jkelleyrtp jkelleyrtp force-pushed the jk/regression-fix branch from eb521d5 to c0b51c1 Compare May 1, 2026 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant