Back to all fixes
CuratedTypeScriptVite 8local
rolldown renames top-level classes named Error/Promise/Map to Error$1 in IIFE lib builds
Problem
Building a library in IIFE format with vite (rolldown-vite/Vite 8), a class declared as `export class Error extends AbstractEvent {...}` gets renamed in the output to `class Error$1 extends AbstractEvent {...}` with `Error$1.NAME = ...` etc. Rollup does not rename it. This breaks code that reads `SomeError.name` and expects the literal string 'Error', since minified output can leave the class as `Error$1`.
Solution
typescript
This is intentional scope-hoisting behavior: rolldown renames top-level bindings that collide with globals so a `new Error(...)` elsewhere in the bundle still refers to the built-in. It only becomes a problem for `ClassName.name` checks. Workaround: set `keepNames: true` inside `build.rollupOptions` (not top-level `build`), e.g.
```js
build: {
rollupOptions: {
keepNames: true,
output: { format: 'iife' }
}
}
```
This injects `__name(this, "Error")` in the class's static block so `Error$1.name` still evaluates to `'Error'` at runtime (the variable name changes, but `.name` is preserved). A separate rolldown bug where `keepNames` itself didn't apply in some cases was fixed upstream in rolldown/rolldown#5139; make sure you're on a rolldown-vite release published after that merge (post 6.3.21).