Skip to content

[Bug]: __commonJSMin is not a function — runtime helper lifted into entry chunk again in 1.1.2 (regression of #9224) #9993

Description

@thevuong

Reproduction link or steps

This is a regression in rolldown 1.1.2 of the bug fixed for #9224 (which was itself a rc.17 regression from rc.15). The runtime CJS-interop helper (__commonJSMin) is once again lifted into the entry chunk and re-imported by a code-split CJS chunk that is evaluated before the entry body runs, so the helper is still uninitialized at the call site → TypeError: __commonJSMin is not a function.

I don't have a minimal REPL (same as #9224 — the trigger is a real dependency graph), but the before/after is fully deterministic. It surfaces via vite, whose only dependency delta between the working and broken versions is the bundled rolldown:

vite bundled rolldown result
8.0.16 1.0.3 ✅ works
8.1.0 ~1.1.2 __commonJSMin is not a function

Stack (TanStack Start SSR prerender of a Vite app; Node ESM evaluating the server function):

TypeError: __commonJSMin is not a function
    at .../functions/__server.func/_libs/@tanstack/react-router+[...].mjs:3917:71
    at .../functions/__server.func/recharts+[...].mjs:15:71

The before/after that pins it

rolldown 1.0.3 (works) — helper lives in a dedicated leaf runtime module _runtime.mjs (no imports → always initialized before any consumer):

// _libs/recharts+[...].mjs
import { n as __exportAll } from "../_runtime.mjs";   // leaf helper module, no cycle

rolldown 1.1.2 (broken) — helper is inlined into the server entry _ssr/ssr.mjs (hoisted var, exported as s) and re-imported by sibling chunks:

// recharts+[...].mjs  (and _libs/@tanstack/react-router+[...].mjs, etc.)
import { c as __exportAll, l as __require, s as __commonJSMin, u as __toESM } from "./_ssr/ssr.mjs";
//                                          ^^^^^^^^^^^^^^^^^ imported from the ENTRY chunk
var require_use_sync_external_store_shim_production = __commonJSMin((exports) => { ... }); // top-level call

// _ssr/ssr.mjs  (the entry)
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);  // line 14
...
export { ..., __commonJSMin as s, ... };

Because _ssr/ssr.mjs is the entry, it imports the route/lib chunks at its top; ESM evaluates those imports depth-first before the entry body assigns the var __commonJSMin, so the live binding is still undefined when the sibling chunk runs its top-level __commonJSMin(...).

This is exactly the cycle shape described in #9224. It reproduces with default chunking — removing a manual output.codeSplitting.groups entry for one library just moves the failure to the next CJS-wrapped sibling chunk (e.g. @tanstack/react-router), confirming it is the general runtime-helper-in-entry placement, not a specific group config (so it is distinct from the advancedChunks-specific #9887, though likely the same underlying cause).

What is expected?

The __commonJSMin/__commonJS runtime helper should be emitted so it is initialized before any consumer — e.g. inlined into the chunk that needs it, or kept in a dependency-free leaf module like rolldown 1.0.3 emitted (_runtime.mjs) — never lifted into an entry chunk that imports its own consumers, which creates the circular ESM init.

What is actually happening?

In rolldown 1.1.2 the helper is placed in the entry chunk and imported by code-split CJS chunks that execute first, throwing __commonJSMin is not a function at module-init. Pinning rolldown back to 1.0.3 (via vite 8.0.16) avoids it.

Versions

  • rolldown 1.1.2 (broken) / 1.0.3 (works), as bundled by vite 8.1.0 / 8.0.16
  • @tanstack/react-start SSR prerender, nitro 3.0.260610-beta, Node 24/26

Metadata

Metadata

Assignees

Type

No type

Fields

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions