Turbopack fails to tree-shake unused enums due to scope hoisting issues.
The issue involves Turbopack not properly tree-shaking unused enums from the final bundle, specifically when scope hoisting is enabled. This results in larger bundle sizes compared to Webpack. The problem appears to be related to scope hoisting losing `/*#__PURE__*/` comments during the process.
https://github.com/DRoet/turbo-treeshake-bug
Create project with client component that imports large .ts file with loads of enum definitions that are not being used. (see listed repository
next buildnext experimental-analyzelarge-utility.ts will be listed as ~20kb, none of the unused enums are strippedI would expect the unused enums to be stripped from the final bundle just like next build --webpack
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
Turbopack
next build (local)
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
Claim this issue to let others know you're working on it. You'll earn 30 points when you complete it!