Back to all fixes
CuratedExecution-verifiedTypeScriptVite 8local

Vite 8 fails to tree-shake a boolean constant derived from import.meta.env.MODE via an intermediate or cross-module variable

Problem

In Vite 8, code like `const ENABLE_X = MODE === 'foo' || MODE === 'bar'` (where MODE comes from `import.meta.env.MODE` via an intermediate const, especially one imported from another module) is not tree-shaken away in production even when the condition is statically false, bloating bundle size (e.g. 55KB in Vite 7 vs 900KB in early Vite 8). Vite 7/Rollup+terser correctly eliminated the dead branch.

Solution

typescript
Partial fix landed in Rolldown v1.1.2/Vite 8.1.0 for the case where MODE is used directly or via a same-module const (bundle size drops back close to Vite 7 levels). Workaround for the remaining unresolved case (MODE re-exported from a separate module): set `build.minify: 'terser'` instead of the default esbuild/oxc minifier - confirmed by the reporter to fully eliminate the dead code. The cross-module case is still tracked upstream (oxc-project/oxc#17364, #23777) for a full native-minifier fix.