nextjs - ✅(Solved) Fix Turbopack generates invalid bundle when using browserslist with latest caniuse-lite [3 pull requests, 7 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#86076Fetched 2026-04-08 02:12:42
View on GitHub
Comments
7
Participants
4
Timeline
26
Reactions
1
Timeline (top)
commented ×7labeled ×6subscribed ×4cross-referenced ×3

Error Message

This may be a bit noisy, but if we extract the diff, we can see that the char() function, which is defined in the stylist module, is not being resolved correctly, resulting in an undefined error for char(). Even if we try to skip the stylis where this error occurs, similar errors occur in other places, so it seems that there is some kind of bug in turbopack. The above error disappears with the following changes I'm not sure that this is an error of turbopack or SWC. But I think something about bundling or compiling is wrong in some conditions.

Fix Action

Fixed

PR fix notes

PR #11330: fix(es/compat): Preserve SyntaxContext in ES3 reserved word transformation

Description (problem / solution / changelog)

Summary

This PR improves the ES3 reserved word transformation pass to explicitly preserve SyntaxContext when renaming identifiers that are reserved in ES3 (like char, byte, int, etc.).

Problem

The ES3 reserved word transformation renames identifiers by prefixing them with underscore. The previous implementation directly modified the sym field:

i.sym = format!("_{}", i.sym).into()

While this did preserve the ctxt field implicitly, it was not as explicit and clear as using the dedicated with_prefix method available on the Ident struct.

Solution

Use Ident::with_prefix("_") instead of direct sym field modification:

*i = i.with_prefix("_");

The with_prefix method (defined in crates/swc_ecma_ast/src/ident.rs:388-394) explicitly preserves the SyntaxContext and Span when creating the new identifier, making the intent clear and following Rust best practices.

Changes

  • Modified visit_mut_ident in reserved_word.rs to use with_prefix method
  • Added comprehensive test cases:
    • nextjs_issue_86076: Tests multiple ES3 reserved words in exports (function, const, class)
    • multiple_reserved_words: Tests multiple reserved word functions exported together
    • reserved_var_declarations: Tests variable declarations with reserved words

Testing

All existing tests pass, and new tests verify the transformation works correctly for various scenarios:

cargo test -p swc_ecma_compat_es3

Related Issues

  • Addresses Next.js issue vercel/next.js#86076 where Turbopack generated invalid JavaScript when bundling with browserslist + caniuse-lite
  • The transformation correctly handles ES3 reserved words while maintaining proper scope tracking through SyntaxContext preservation

🤖 Generated with Claude Code

Changed files

  • crates/swc_ecma_compat_es3/src/reserved_word.rs (modified, +49/-1)
  • crates/swc_ecma_compat_es3/tests/__swc_snapshots__/src/reserved_word.rs/multiple_reserved_words.js (added, +10/-0)
  • crates/swc_ecma_compat_es3/tests/__swc_snapshots__/src/reserved_word.rs/nextjs_issue_86076.js (added, +10/-0)
  • crates/swc_ecma_compat_es3/tests/__swc_snapshots__/src/reserved_word.rs/reserved_var_declarations.js (added, +4/-0)

PR #86532: fix(turbopack): Disable ES3 transforms from preset-env

Description (problem / solution / changelog)

What?

Disable es3 transforms while applying preset-env.

Why?

It's not required for turbopack. I'll remove them completely from the binary in the future.

How?

Fixes #86076

Changed files

  • turbopack/crates/turbopack-ecmascript/src/transform/mod.rs (modified, +8/-1)

PR #86573: Turbopack: import to char not replaced

Description (problem / solution / changelog)

Adds a test case for #86532 , #86076

Changed files

  • turbopack/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env_modern/input/Parser.js (added, +5/-0)
  • turbopack/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env_modern/input/Tokenizer.js (added, +3/-0)
  • turbopack/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env_modern/input/index.js (added, +3/-0)
  • turbopack/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env_modern/options.json (added, +3/-0)
  • turbopack/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env_modern/output/780ce_turbopack-tests_tests_snapshot_swc_transforms_preset_env_modern_input_e3b65cb8._.js (added, +36/-0)
  • turbopack/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env_modern/output/780ce_turbopack-tests_tests_snapshot_swc_transforms_preset_env_modern_input_e3b65cb8._.js.map (added, +8/-0)
  • turbopack/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env_modern/output/ad3e4_tests_snapshot_swc_transforms_preset_env_modern_input_index_a3dbfd52.js (added, +5/-0)
  • turbopack/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env_modern/output/bf321_tests_snapshot_swc_transforms_preset_env_modern_input_index_a3dbfd52.js.map (added, +5/-0)

Code Example

// with [email protected]

function comment(value, root, parent, siblings) {
    return (0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Tokenizer$2e$js__$5b$client$5d$__$28$ecmascript$29$__["node"])(value, root, parent, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Enum$2e$js__$5b$client$5d$__$28$ecmascript$29$__["COMMENT"], (0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Utility$2e$js__$5b$client$5d$__$28$ecmascript$29$__["from"])((0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Tokenizer$2e$js__$5b$client$5d$__$28$ecmascript$29$__["char"])()), (0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Utility$2e$js__$5b$client$5d$__$28$ecmascript$29$__["substr"])(value, 2, -2), 0, siblings);
}

---

// with [email protected]

function comment(value, root, parent, siblings) {
    return (0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Tokenizer$2e$js__$5b$client$5d$__$28$ecmascript$29$__["node"])(value, root, parent, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Enum$2e$js__$5b$client$5d$__$28$ecmascript$29$__["COMMENT"], (0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Utility$2e$js__$5b$client$5d$__$28$ecmascript$29$__["from"])(char()), (0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Utility$2e$js__$5b$client$5d$__$28$ecmascript$29$__["substr"])(value, 2, -2), 0, siblings);
}

---

- __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Tokenizer$2e$js__$5b$client$5d$__$28$ecmascript$29$__["char"])()
+ char()

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Wed Oct 15 21:12:44 PDT 2025; root:xnu-11417.140.69.703.14~1/RELEASE_ARM64_T8112
  Available memory (MB): 24576
  Available CPU cores: 8
Binaries:
  Node: 22.10.0
  npm: 10.9.0
  Yarn: N/A
  pnpm: 9.15.3
Relevant Packages:
  next: 16.0.2 // Latest available version is detected (16.0.2).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/KentoMoriwaki/turbopack-caniuse-repro

To Reproduce

Clone https://github.com/KentoMoriwaki/turbopack-caniuse-repro and follow README.md

Current vs. Expected behavior

Currently it produces broken bundle. It is expected to produce correct bundle.

before

// with [email protected]

function comment(value, root, parent, siblings) {
    return (0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Tokenizer$2e$js__$5b$client$5d$__$28$ecmascript$29$__["node"])(value, root, parent, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Enum$2e$js__$5b$client$5d$__$28$ecmascript$29$__["COMMENT"], (0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Utility$2e$js__$5b$client$5d$__$28$ecmascript$29$__["from"])((0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Tokenizer$2e$js__$5b$client$5d$__$28$ecmascript$29$__["char"])()), (0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Utility$2e$js__$5b$client$5d$__$28$ecmascript$29$__["substr"])(value, 2, -2), 0, siblings);
}

after

// with [email protected]

function comment(value, root, parent, siblings) {
    return (0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Tokenizer$2e$js__$5b$client$5d$__$28$ecmascript$29$__["node"])(value, root, parent, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Enum$2e$js__$5b$client$5d$__$28$ecmascript$29$__["COMMENT"], (0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Utility$2e$js__$5b$client$5d$__$28$ecmascript$29$__["from"])(char()), (0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Utility$2e$js__$5b$client$5d$__$28$ecmascript$29$__["substr"])(value, 2, -2), 0, siblings);
}

This may be a bit noisy, but if we extract the diff, we can see that the char() function, which is defined in the stylist module, is not being resolved correctly, resulting in an undefined error for char().

- __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$stylis$40$4$2e$3$2e$2$2f$node_modules$2f$stylis$2f$src$2f$Tokenizer$2e$js__$5b$client$5d$__$28$ecmascript$29$__["char"])()
+ char()

It is unclear why this is happening, but it started occurring when the caniuse-lite version was bumped to 1.0.30001754. Even if we try to skip the stylis where this error occurs, similar errors occur in other places, so it seems that there is some kind of bug in turbopack.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Wed Oct 15 21:12:44 PDT 2025; root:xnu-11417.140.69.703.14~1/RELEASE_ARM64_T8112
  Available memory (MB): 24576
  Available CPU cores: 8
Binaries:
  Node: 22.10.0
  npm: 10.9.0
  Yarn: N/A
  pnpm: 9.15.3
Relevant Packages:
  next: 16.0.2 // Latest available version is detected (16.0.2).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

SWC, Turbopack, Pages Router, Module Resolution

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

The above error disappears with the following changes

  • Remove browserslist field from package.json
  • Or downgrade caniuse-lite to 1.0.30001753 or earlier

I'm not sure that this is an error of turbopack or SWC. But I think something about bundling or compiling is wrong in some conditions.

extent analysis

TL;DR

The issue can be temporarily resolved by downgrading caniuse-lite to version 1.0.30001753 or earlier, or by removing the browserslist field from package.json.

Guidance

  1. Verify the issue: Confirm that the problem occurs when caniuse-lite is version 1.0.30001754 or later and the browserslist field is present in package.json.
  2. Downgrade caniuse-lite: Try downgrading caniuse-lite to version 1.0.30001753 or earlier to see if the issue is resolved.
  3. Remove browserslist field: Remove the browserslist field from package.json to check if the issue is related to browser list configuration.
  4. Investigate Turbopack and SWC: Since the issue seems to be related to bundling or compiling, investigate the configurations and versions of Turbopack and SWC to ensure they are compatible with the project setup.

Example

No specific code example is provided as the issue seems to be related to configuration and dependencies rather than code.

Notes

The root cause of the issue is unclear, but it appears to be related to the interaction between caniuse-lite, Turbopack, and SWC. Further investigation is needed to determine the exact cause and a permanent solution.

Recommendation

Apply the workaround by downgrading caniuse-lite to version 1.0.30001753 or earlier, as this has been confirmed to resolve the issue temporarily. This will allow the project to continue functioning while a more permanent solution is investigated.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - ✅(Solved) Fix Turbopack generates invalid bundle when using browserslist with latest caniuse-lite [3 pull requests, 7 comments, 4 participants]