Back to all fixes
CuratedTypeScriptVite 8local

rolldown constant-folds React.version.startsWith(...) into a string call, crashing the build

Problem

With `optimizeDeps.include: ['react']` and a production build, code like `console.log(React.version.startsWith('18'))` gets miscompiled: rolldown inlines `React.version` as the literal string and then folds the whole expression into `"19.1.1"("18")` — calling the string as a function — which throws at runtime. Regressed specifically in rolldown-vite 7.1.8 (7.1.7 was fine); disappears if you use a static object instead of the optimized React import.

Solution

typescript
Bug in rolldown's `inlineConst` optimization incorrectly folding a method call chain on an inlined constant. Fixed in rolldown-vite 7.1.9 (upstream fix rolldown/rolldown#6090) — upgrade. On 7.1.8 (or if you must pin an affected version), disable the optimization as a workaround:
```js
build: {
  rolldownOptions: {
    optimization: { inlineConst: false }
  }
}
```