Back to all fixes
CuratedTypeScriptVite 8local

Vite 8 build breaks namespace imports of CJS packages with side-effect export mutation (e.g. backbone-relational)

Problem

`import * as Backbone from 'backbone'; import 'backbone-relational'` builds fine in dev but throws `TypeError: can't access property "extend", ... is undefined` in the Vite 8 production build. Root cause: Rolldown's CJS namespace import snapshots `module.exports` before a later CJS side-effect import (like backbone-relational) mutates the same exports object, so the namespace binding misses the mutation.

Solution

typescript
Workaround confirmed by a maintainer: switch from a namespace import to a default import for the base package - `import Backbone from 'backbone'; import 'backbone-relational';` then use `Backbone.RelationalModel` as normal. Default/named imports read the live CJS export object and see the later mutation, whereas `import * as` does not. Durable fix is pending upstream in rolldown/rolldown#9512; no Vite-side config flag exists yet.