-
Notifications
You must be signed in to change notification settings - Fork 279
Description
Describe the bug
@vue/test-utils fails to find @vue/compiler-dom when testing components with slots in a pnpm workspace with strict hoist settings (hoist: false and shamefullyHoist: false).
The error occurs because @vue/compiler-dom is not listed in @vue/test-utils's peerDependencies, so pnpm cannot properly resolve it in strict hoist mode. This issue specifically manifests when using the slots option in mount(), as @vue/test-utils requires @vue/compiler-dom to compile slot content.
Reproduction
I've created a GitHub repository for reproduction instead of StackBlitz, as setting up pnpm's strict hoist configuration in StackBlitz proved challenging.
https://github.com/kimulaco/vue-test-utils-peer-dependencies-example
To reproduce:
- Clone the repository
- Run
pnpm install - Run
pnpm test
Error output:
Error: Cannot find module `@vue/compiler-dom`
Require stack:
- node_modules/.pnpm/@vue+test-utils@2.4.6/node_modules/`@vue/test-utils`/dist/vue-test-utils.cjs.js
You can also verify this error in CI: https://github.com/kimulaco/vue-test-utils-peer-dependencies-example/actions/runs/20521381439/job/58957183490
Expected behavior
@vue/test-utils should be able to resolve @vue/compiler-dom when testing components with slots. Adding @vue/compiler-dom to @vue/test-utils's peerDependencies would allow pnpm to properly resolve the dependency in strict hoist environments.
Environment
System:
OS: macOS 26.1
CPU: (8) arm64 Apple M2
Memory: 350.02 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
npmPackages:
@vue/test-utils: ^2.4.6 => 2.4.6
vitest: ^4.0.16 => 4.0.16
vue: ^3.5.26 => 3.5.26
Additional context
This issue occurs specifically with pnpm's strict hoist configuration (hoist: false, shamefullyHoist: false) when testing components that use slots. The error only manifests when using the slots option in mount(), as @vue/test-utils requires @vue/compiler-dom to compile slot content.
A workaround exists using pnpm's packageExtensions feature, which is demonstrated in the solution branch: https://github.com/kimulaco/vue-test-utils-peer-dependencies-example/tree/refs/heads/solution
The solution branch shows that adding @vue/compiler-dom to peerDependencies via packageExtensions resolves the issue: https://github.com/kimulaco/vue-test-utils-peer-dependencies-example/actions/runs/20521490248/job/58957444615
However, this should be fixed at the package level by adding @vue/compiler-dom to @vue/test-utils's peerDependencies in package.json.
Note: There is a similar issue #2107 related to yarn berry. While the symptoms appear similar (missing @vue/compiler-dom), it's unclear if this is the same root cause since yarn and pnpm handle dependency resolution differently. I'm filing this as a separate issue for pnpm specifically, but they may be related and could potentially be resolved by the same fix.
I'm happy to create a PR to add @vue/compiler-dom to peerDependencies if this is confirmed as a bug.