Back to all fixes
CuratedTypeScriptVite 8local

Vite 8 dev server incorrectly unwraps CJS default export, causing "Minified React error #130" or undefined component

Problem

A CJS dependency using the `__esModule` + `exports.default` pattern gets its default export incorrectly unwrapped to the inner value in dev (returning the raw object instead of `{ default: ... }`), while build/preview does the opposite (unwraps when it shouldn't), producing an inconsistency between dev and prod. Symptom includes React error #130 (element type is invalid) or `undefined` where a default-exported component/value was expected.

Solution

typescript
This stems from Vite 8's new CommonJS interop rules (see the migration guide's 'Consistent CommonJS interop' section) interacting with `isNodeMode` detection differently between dev's import-analysis and Rolldown's build output. No single core fix was landed in this thread; the confirmed workaround (used by the reporter) is to avoid relying on default-import unwrapping for these CJS packages:
- Prefer named imports where the package provides them, or
- Add a runtime fallback: `import pkgDefault from 'pkg'; const value = pkgDefault.default ?? pkgDefault;`
Apply this consistently so the same code works whether dev unwraps or not.