#11068·rolldown

[Bug]: -mergeCommonChunks- removing an empty dynamic-entry facade creates a circular chunk import

Author: OriolInvernonLlanezaCreated Oct 1, 2026Updated Oct 1, 2026
Labelsneeds-triage

Reproduction link or steps

Disclosure: bug found and text written with help from ClaudeAI.

Reproduction

REPL

StackBlitz

javascript
// src/main.js
globalThis.load = [
  () => import('./barrel.js').then((m) => m.NAME),
  () => import('./page.js'),
];

// src/barrel.js
export * from './types.js';
export { NAME } from './name.js';

// src/types.js
export * from './helpers.js';

// src/helpers.js
export const shout = (s) => s.toUpperCase();

// src/name.js
export const NAME = 'layers';

// src/page.js
import { NAME, shout } from './barrel.js';
export const TITLE = shout(NAME);
javascript
// build.mjs
import { rolldown } from "rolldown";

const mergeCommonChunks = process.argv[2] !== "--no-merge";
const bundle = await rolldown({
  input: "src/main.js",
  experimental: { chunkOptimization: { mergeCommonChunks } },
});
const { output } = await bundle.write({ dir: "dist", format: "es", chunkFileNames: "[name].js" });
for (const chunk of output) {
  if (chunk.type === "chunk") console.log(`${chunk.fileName}: imports [${chunk.imports.join(", ")}]`);
}

Actual

$ node build.mjs
main.js: imports []
barrel.js: imports [page.js]
page.js: imports [barrel.js]

$ node -e 'import("./dist/barrel.js")'
ReferenceError: Cannot access 'NAME' before initialization

What is expected?

No circular chunk import, as with mergeCommonChunks: false. The mergeCommonChunks docs say the merge is applied only "when it does not create a circular chunk dependency".

What is actually happening?

However, as the chunk graph shows, a circular dependency is created between them and the app breaks (in my case based on which chunk loads first).

System Info

bash
System:
    OS: macOS 26.0.1
    CPU: (10) arm64 Apple M4
    Memory: 69.42 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.17.0 - /Users/oriolinvernon/.nvm/versions/node/v22.17.0/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 11.4.2 - /Users/oriolinvernon/.nvm/versions/node/v22.17.0/bin/npm
    pnpm: 11.16.0 - /opt/homebrew/bin/pnpm
    bun: 1.3.12 - /Users/oriolinvernon/.bun/bin/bun
  Browsers:
    Chrome: 154.0.8037.59
    Firefox: 156.0.1
    Safari: 26.0.1

Any additional comments?

Found in a Vite 8.0.14 app on Rolldown 1.0.2, where the loop spanned seven chunks. Which chunk the browser entered first depended on which of two lazy imports won a race at startup, so the crash appeared on some page loads only. We work around it with experimental.chunkOptimization: { mergeCommonChunks: false }; output.strictExecutionOrder: true also avoids the crash.

Sorry if it's not a bug, I'm not really familiar with Rolldown yet.

Possibly related: #9525, #9963 and #10905.