Vitest "Cannot find dependency @vitest/coverage-v8"
Vitest does not ship coverage providers in its core package. When you run --coverage, it tries to load @vitest/coverage-v8 (or -istanbul) and fails if that peer package is not installed or version-matched.
What this error means
vitest run --coverage aborts with "Cannot find dependency '@vitest/coverage-v8'" or a prompt to install it. Tests run fine without --coverage; only the coverage step fails.
Error: Cannot find dependency '@vitest/coverage-v8'
Please install @vitest/coverage-v8 to use the 'v8' coverage provider.Common causes
Coverage provider not installed
The provider (@vitest/coverage-v8 or @vitest/coverage-istanbul) is a separate package. CI runs --coverage but the provider was never added to devDependencies.
Provider version drift from vitest
The coverage package must match the installed vitest version. A mismatched major can fail to resolve or load, surfacing the same error.
How to fix it
Install the provider at a matching version
npm install -D @vitest/coverage-v8
# keep it pinned to the same version as vitest
npm install -D @vitest/coverage-v8@${'$'}(node -p "require('vitest/package.json').version")Select the provider in config
// vitest.config.ts
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: { coverage: { provider: 'v8', reporter: ['text', 'lcov'] } },
});How to prevent it
- Add the coverage provider to devDependencies alongside vitest.
- Pin the provider to the same version as
vitest. - Run
--coveragein CI so a missing provider is caught early.