Skip to content

gkurt/rolldown-checkglobals-repro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rolldown drops a referenced cross-module binding under strictExecutionOrder + sideEffects: false

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.

Repro

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"

What happens

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.

Expected

The referenced checkGlobals definition must be retained whenever the call is retained, regardless of sideEffects: false.

Version matrix

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.

Trigger conditions (all required)

  • 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

About

Minimal repro: rolldown (vite 8.1.0) drops a referenced cross-module binding under strictExecutionOrder + sideEffects:false, causing a ReferenceError

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors