Skip to content

[Bug]: Dep optimizer: missing init_shared_esm_bundler import in @vue/test-utils chunk when @vue/compiler-dom is split as a CJS-interop sub-chunk #9502

Description

@alfeg

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:
    1. @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.
    2. 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

Metadata

Metadata

Type

Fields

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions