-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Labels
Description
Describe the bug
Starting with @vitest/mocker 4.1.0, running vitest with @vitest/browser-playwright fails with ERR_MODULE_NOT_FOUND if vite is not explicitly installed in the project, even though vite is declared as an optional peer dependency.
Expected: Tests run (or a graceful error if vite is required)
Actual:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'vite' imported from /path/to/node_modules/@vitest/browser-playwright/node_modules/@vitest/mocker/dist/node.js
Root cause
In @vitest/mocker/package.json, vite is declared as optional:
"peerDependencies": {
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0-0"
},
"peerDependenciesMeta": {
"vite": {
"optional": true
}
}However, dist/node.js appears to have an unconditional static import of vite, causing Node.js module resolution to fail immediately at load time when vite is not present.
This worked in 4.0.18
Workaround
Explicitly install vite as a devDependency:
npm install vite --save-devReproduction
https://stackblitz.com/edit/vitest-dev-vitest-bjtmmvai?file=package.json&initialPath=__vitest__/
- Create a project with the following devDependencies:
{ "devDependencies": { "@vitest/browser-playwright": "4.1.0", "vitest": "4.1.0" } } - Run
npm install - Run
vitest
System Info
System:
OS: macOS 26.3.1
CPU: (12) arm64 Apple M4 Pro
Memory: 8.55 GB / 48.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.22.1 - /usr/local/bin/node
npm: 10.9.4 - /usr/local/bin/npm
Browsers:
Chrome: 146.0.7680.153
Safari: 26.3.1
npmPackages:
@vitest/browser-playwright: 4.1 => 4.1.0
vitest: 4.1 => 4.1.0Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable