Upstream issue: rolldown/rolldown#9961
Minimal reproduction of a rolldown (via vite@8.1.0) bundling bug: a top-level
side-effect call is retained, but the imported function definition it
references is tree-shaken out of every chunk, producing a dangling reference and
a runtime ReferenceError.
Triggered in the wild by msw: its
core/index.mjs calls checkGlobals() at module top level, while its
package.json declares "sideEffects": false.
npm install
npm run build
# ReferenceError visible in the bundle:
grep -c 'checkGlobals()' dist/assets/*.js # => 1 (the call is kept)
grep -c 'function checkGlobals' dist/assets/*.js # => 0 (the definition is gone)
npm run preview # open the page -> blank, console: "ReferenceError: checkGlobals is not defined"msw's node_modules/msw/lib/core/index.mjs:
import { checkGlobals } from './utils/internal/checkGlobals.mjs';
// ...
checkGlobals(); // <-- top-level side effect
export { http, HttpResponse, /* ... */ };msw's package.json has "sideEffects": false. With
build.rolldownOptions.output.strictExecutionOrder: true, rolldown keeps the
checkGlobals() call (its module is retained because other exports are used)
but removes the checkGlobals function definition from checkGlobals.mjs.
The call becomes a free identifier → ReferenceError.
The referenced checkGlobals definition must be retained whenever the call is
retained, regardless of sideEffects: false.
| vite | rolldown | result |
|---|---|---|
| 8.1.0 | 1.1.3 | ❌ definition dropped, ReferenceError |
| 8.0.16 | 1.0.3 | ✅ definition retained, works |
Regression between rolldown 1.0.3 and 1.1.3.
output.strictExecutionOrder: true— without it both call and definition are dropped together (no dangling reference)- the dependency declares
"sideEffects": false - that dependency calls an imported cross-module function at its module top level
- other exports of the dependency are used, so its module is retained