nextjs - ✅(Solved) Fix Turbopack not tree-shaking unused enum exports [2 pull requests, 5 comments, 3 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#88009Fetched 2026-04-08 02:05:40
View on GitHub
Comments
5
Participants
3
Timeline
18
Reactions
0
Author
Timeline (top)
commented ×5subscribed ×5mentioned ×3cross-referenced ×2

Fix Action

Fixed

PR fix notes

PR #88205: Turbopack: properly remove unused TS enums with scope hoisting

Description (problem / solution / changelog)

Only adds a test so far

Closes https://github.com/vercel/next.js/issues/88009 Closes PACK-6424

Changed files

  • turbopack/crates/turbopack-tests/tests/execution/turbopack/scope-hoisting/pure-comments/input/a.ts (added, +3/-0)
  • turbopack/crates/turbopack-tests/tests/execution/turbopack/scope-hoisting/pure-comments/input/index.js (added, +13/-0)
  • turbopack/crates/turbopack-tests/tests/execution/turbopack/scope-hoisting/pure-comments/options.json (added, +3/-0)

PR #90004: Turbopack: properly remove unused TS enums with scope hoisting

Description (problem / solution / changelog)

<!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->

Attempt based on https://github.com/vercel/next.js/pull/88205. reserves SWC sentinel spans during scope-hoisting so PURE annotations survive module merging.

Closes https://github.com/vercel/next.js/issues/88009 Closes PACK-6424

@mischnic PTAL if this is the right approach

Changed files

  • turbopack/crates/turbopack-ecmascript/src/lib.rs (modified, +8/-0)
  • turbopack/crates/turbopack-tests/tests/execution/turbopack/scope-hoisting/pure-comments/input/a.ts (added, +3/-0)
  • turbopack/crates/turbopack-tests/tests/execution/turbopack/scope-hoisting/pure-comments/input/index.js (added, +17/-0)
  • turbopack/crates/turbopack-tests/tests/execution/turbopack/scope-hoisting/pure-comments/options.json (added, +3/-0)

Code Example

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 63146
  Available CPU cores: 16
Binaries:
  Node: 24.11.0
  npm: 11.6.1
  Yarn: 1.22.22
  pnpm: 9.15.5
Relevant Packages:
  next: 16.1.1 // Latest available version is detected (16.1.1).
  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/DRoet/turbo-treeshake-bug

To Reproduce

Create project with client component that imports large .ts file with loads of enum definitions that are not being used. (see listed repository

  1. In the listed repository, run next build
  2. check the Turbopack bundle output using the new analyze command: next experimental-analyze
  3. large-utility.ts will be listed as ~20kb, none of the unused enums are stripped

Current vs. Expected behavior

I would expect the unused enums to be stripped from the final bundle just like next build --webpack

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 63146
  Available CPU cores: 16
Binaries:
  Node: 24.11.0
  npm: 11.6.1
  Yarn: 1.22.22
  pnpm: 9.15.5
Relevant Packages:
  next: 16.1.1 // Latest available version is detected (16.1.1).
  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)

Turbopack

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

next build (local)

Additional context

In our large repository we have a lot of GraphQL-Codegen with enums, so in our case its adding ~300kb to the final output compared to webpack

extent analysis

TL;DR

The issue can be mitigated by using a different build configuration or exploring tree-shaking options in Turbopack.

Guidance

  • Investigate the next build configuration to see if there are any options that can be used to enable tree-shaking for enums.
  • Compare the build configurations between next build and next build --webpack to identify any differences that may be causing the issue.
  • Consider using a custom Webpack configuration with Turbopack to enable enum tree-shaking.
  • Review the large-utility.ts file to see if there are any specific patterns or structures that may be preventing tree-shaking from working correctly.

Example

No specific code example is provided as the issue is related to build configuration and tree-shaking behavior.

Notes

The issue may be specific to the combination of Next.js, Turbopack, and TypeScript versions being used. Further investigation is needed to determine the root cause and find a suitable solution.

Recommendation

Apply workaround: The best course of action is to explore different build configurations and tree-shaking options in Turbopack to mitigate the issue, as upgrading to a fixed version is not clearly implied.

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