vitest-dev/vitest · error · Error
Something removed the coverage directory
Error message
Something removed the coverage directory "${coverageFilesDirectory}" Vitest created earlier. Make sure you are not running multiple Vitests with the same "coverage.reportsDirectory" at the same time. What it means
Same guard as the istanbul provider but emitted by the v8 coverage provider's writeCoverageFile. writeFile to the coverage JSON fails and the coverage directory it created earlier no longer exists, pointing at a concurrent remover of reportsDirectory.
Solutions
- Use a unique coverage.reportsDirectory per concurrent run/shard, then merge coverage outputs.
- Avoid deleting the coverage directory while a run is in progress; clean only before the run.
- Run coverage-producing suites sequentially if sharding/merging is not set up.
Example fix
// before
export default defineConfig({ test: { coverage: { provider: 'v8', reportsDirectory: './coverage' } } })
// after
export default defineConfig({ test: { coverage: { provider: 'v8', reportsDirectory: './coverage/shard-1' } } }) Defensive patterns
Strategy: validation
Validate before calling
import { existsSync, mkdirSync } from 'node:fs'
function ensureCoverageDir(dir) {
if (!existsSync(dir)) mkdirSync(dir, { recursive: true })
} Try / catch
try {
await vitestRun()
} catch (e) {
if (/removed the coverage directory/.test(String(e?.message))) {
throw new Error('Coverage dir lost to a concurrent run; use a unique reportsDirectory.')
}
throw e
} Prevention
- Namespace v8 coverage.reportsDirectory per run/shard.
- Avoid parallel runs that clean the same coverage directory.
- Merge coverage from sharded directories only after all runs complete.
When it happens
Trigger: writeCoverageFile(coverageFilesDirectory, coverage) in packages/coverage-v8 calls writeFile, it throws, and existsSync(coverageFilesDirectory) is false.
Common situations: Parallel Vitest workers/projects sharing one v8 coverage.reportsDirectory; a watcher rerun colliding with coverage cleanup; CI cleanup between parallel shards overwriting the same directory.
Related errors
- Something removed the coverage directory
- Failed to load . Default export is missing.
- You cannot set "coverage.reportsDirectory" as
- Access denied to " ". See Vite config documentation for…
- Access denied to " ". See Vite config documentation for…
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/ad60f6385d09b711.
Report an issue: GitHub.
Appendix: source
Thrown at packages/coverage-v8/src/commands.ts:54
const provider = context.project.vitest.coverageProvider as V8CoverageProvider
return await writeCoverageFile(provider.coverageFilesDirectory, { result })
}
export async function writeCoverageFile(coverageFilesDirectory: string, coverage: unknown): Promise<string> {
// Write results on file system directly and transfer only the filename over RPC
const filename = resolve(
coverageFilesDirectory,
`coverage-${randomUUID()}.json`,
)
try {
await writeFile(filename, JSON.stringify(coverage), 'utf-8')
}
catch (error) {
if (!existsSync(coverageFilesDirectory)) {
throw new Error(
`Something removed the coverage directory "${coverageFilesDirectory}" Vitest created earlier. Make sure you are not running multiple Vitests with the same "coverage.reportsDirectory" at the same time.`,
{ cause: error },
)
}
throw error
}
return filename
}
function filterResult(url: string, origin: string, pageUrl: string): boolean {
if (!url.startsWith(origin)) {
return false
}
if (url.includes('/node_modules/')) {
return falseView on GitHub (pinned to 1fa9837ec2)