Visitar URL original
[Bug]: `export var` read across a circular import before its declaration executes is inlined with its initializer · Issue #11549 · rolldown/rolldown · GitHub
Skip to content

[Bug]: export var read across a circular import before its declaration executes is inlined with its initializer #11549

Open

Description

@trackoor

Reproduction link or steps

https://gist.github.com/trackoor/baf90abba16464bf5ad4cf222fa79f9b

// main.js
import { early } from './b.js';
export var v = 3;
console.log(early, v);

// b.js
import { v } from './main.js';
export const early = v;
npx rolldown main.js -f es -o bundle.js && node bundle.js

What is expected?

Running node bundle.js prints undefined 3 (matching node main.js, as well as Rollup, esbuild, and webpack), because b.js evaluates before main.js while v is still undefined.

What is actually happening?

In Rolldown 1.3.0 with default options, the never-reassigned export var v = 3 is inlined into b.js (const early = 3;), so running node bundle.js prints 3 3.

System Info

  System:
    OS: macOS 26.3
    CPU: (16) arm64 Apple M3 Max
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.14.1
    npm: 11.11.0
  npmPackages:
    rolldown: 1.3.0 => 1.3.0

Any additional comments?

#11379 stopped inlining a var when module-level code in the same module reads it before its declaration, but cross-module reads in a cycle can still execute before the declaring module's body.

Credit: https://ucsbplse.github.io/

Playground

https://repl.rolldown.rs/#eNptkMFuwjAQRH9ltScqRVuq3FJx6m/44oATGTlrZBwDivzv3bgQQsXNuzM7b+QJO2wmHLRlOp7nJ2OzjBXuZbLDyYcIExgd3A0ydMEPoJA+WzEp/FZsrsWSdIAEO6hltfd89s6Q8/2mHFaQPmQvoQabGEaTK2xX0PYNMa1p91Zr4AyJ9147SHO8pAbv3MFfmETubE9xYbxR/hEPprNsfor8hD/uCnuhi1ePLr7cbCbFAJZPY2zgL5UGEzWVVaU4l0/IUjMJ94tq2mL+BYy1gxs=

The output inlines const early = 3;, so the bundle prints 3 3 instead of undefined 3.

Activity

  1. changed the title [-]`export var` read across a circular import before its declaration executes is inlined with its initializer[/-] [+][Bug]: `export var` read across a circular import before its declaration executes is inlined with its initializer[/+] on Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions