Reproduction link or steps
Here is the minimal repro: https://github.com/alfeg/rolldown-init-bug-repro
What is expected?
For every chunk that contains an init_X() call, the dep optimizer should
also emit the corresponding cross-chunk import binding for init_X — the
same way it does for the sibling chunks @vue/server-renderer,
vue.runtime.esm-bundler, and compiler-dom.esm-bundler, which all
correctly import v as init_shared_esm_bundler from
shared.esm-bundler-*.js.
What is actually happening?
The pre-bundled @vue/test-utils chunk emits the call but the import is
dropped. First lines of node_modules/.vite/vitest/<hash>/deps/@vue_test-utils.js:
import { …, n as vue_runtime_esm_bundler_exports, … } from "./vue.runtime.esm-bundler-XXXX.js";
import { h as compile } from "./compiler-dom.esm-bundler-XXXX.js";
import { renderToString as renderToString$1 } from "./@vue_server-renderer.js";
//#region node_modules/@vue/test-utils/dist/vue-test-utils.esm-bundler.mjs
init_shared_esm_bundler(); // ← never imported → ReferenceError at load
System Info
❯ npx envinfo --system --npmPackages rolldown --binaries --browsers
Need to install the following packages:
envinfo@7.21.0
Ok to proceed? (y) y
System:
OS: Windows 11 10.0.28000
CPU: (16) x64 AMD Ryzen 7 7800X3D 8-Core Processor
Memory: 21.29 GB / 63.16 GB
Binaries:
Node: 24.15.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
npm: 11.11.0 - C:\Program Files\nodejs\npm.CMD
pnpm: 9.6.0 - C:\Program Files\nodejs\pnpm.CMD
bun: 1.3.0 - C:\Users\Victo\.bun\bin\bun.EXE
Deno: 2.6.4 - C:\Users\Victo\.deno\bin\deno.EXE
Browsers:
Chrome: 148.0.7778.168
Edge: Chromium (146.0.3856.97)
Firefox: 150.0.3 - C:\Program Files\Mozilla Firefox\firefox.exe
Any additional comments?
- Two conditions both seem required to trigger the miswire:
@vue/compiler-dom is split into a CJS-interop sub-chunk
(compiler-dom.esm-bundler-<hash>.js with __commonJSMin /
require_compiler_core_cjs()). Vitest's optimizer pass uses
mainFields: [] and drops module from resolve conditions, so
@vue/compiler-core resolves via its node export → CJS.
- The consumer chunk's source has a namespace import:
import * as Vue from "vue". The other consumers use only named
imports and their init_shared_esm_bundler import is wired correctly.
- Downstream impact: every Vitest browser-mode test suite using
@vue/test-utils under Vite 8 crashes at startup, because
@vitest/browser auto-adds @vue/test-utils to optimizeDeps.include.
Created with the help of LLM tools
Reproduction link or steps
Here is the minimal repro: https://github.com/alfeg/rolldown-init-bug-repro
What is expected?
For every chunk that contains an
init_X()call, the dep optimizer shouldalso emit the corresponding cross-chunk import binding for
init_X— thesame way it does for the sibling chunks
@vue/server-renderer,vue.runtime.esm-bundler, andcompiler-dom.esm-bundler, which allcorrectly import
v as init_shared_esm_bundlerfromshared.esm-bundler-*.js.What is actually happening?
The pre-bundled
@vue/test-utilschunk emits the call but the import isdropped. First lines of
node_modules/.vite/vitest/<hash>/deps/@vue_test-utils.js:System Info
Any additional comments?
@vue/compiler-domis split into a CJS-interop sub-chunk(
compiler-dom.esm-bundler-<hash>.jswith__commonJSMin/require_compiler_core_cjs()). Vitest's optimizer pass usesmainFields: []and dropsmodulefrom resolve conditions, so@vue/compiler-coreresolves via itsnodeexport → CJS.import * as Vue from "vue". The other consumers use only namedimports and their
init_shared_esm_bundlerimport is wired correctly.@vue/test-utilsunder Vite 8 crashes at startup, because@vitest/browserauto-adds@vue/test-utilstooptimizeDeps.include.Created with the help of LLM tools