{"record":{"id":"ad60f6385d09b711","repo":"vitest-dev/vitest","slug":"something-removed-the-coverage-directory-covera-ad60f6","errorCode":null,"errorMessage":"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.","messagePattern":"Something removed the coverage directory \"(.+?)\" Vitest created earlier\\. Make sure you are not running multiple Vitests with the same \"coverage\\.reportsDirectory\" at the same time\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coverage-v8/src/commands.ts","lineNumber":54,"sourceCode":"\n  const provider = context.project.vitest.coverageProvider as V8CoverageProvider\n\n  return await writeCoverageFile(provider.coverageFilesDirectory, { result })\n}\n\nexport async function writeCoverageFile(coverageFilesDirectory: string, coverage: unknown): Promise<string> {\n  // Write results on file system directly and transfer only the filename over RPC\n  const filename = resolve(\n    coverageFilesDirectory,\n    `coverage-${randomUUID()}.json`,\n  )\n\n  try {\n    await writeFile(filename, JSON.stringify(coverage), 'utf-8')\n  }\n  catch (error) {\n    if (!existsSync(coverageFilesDirectory)) {\n      throw new Error(\n        `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.`,\n        { cause: error },\n      )\n    }\n\n    throw error\n  }\n\n  return filename\n}\n\nfunction filterResult(url: string, origin: string, pageUrl: string): boolean {\n  if (!url.startsWith(origin)) {\n    return false\n  }\n\n  if (url.includes('/node_modules/')) {\n    return false","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/coverage-v8/src/commands.ts#L36-L72","documentation":"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.","triggerScenarios":"writeCoverageFile(coverageFilesDirectory, coverage) in packages/coverage-v8 calls writeFile, it throws, and existsSync(coverageFilesDirectory) is false.","commonSituations":"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.","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."],"exampleFix":"// before\nexport default defineConfig({ test: { coverage: { provider: 'v8', reportsDirectory: './coverage' } } })\n// after\nexport default defineConfig({ test: { coverage: { provider: 'v8', reportsDirectory: './coverage/shard-1' } } })","handlingStrategy":"validation","validationCode":"import { existsSync, mkdirSync } from 'node:fs'\nfunction ensureCoverageDir(dir) {\n  if (!existsSync(dir)) mkdirSync(dir, { recursive: true })\n}","typeGuard":null,"tryCatchPattern":"try {\n  await vitestRun()\n} catch (e) {\n  if (/removed the coverage directory/.test(String(e?.message))) {\n    throw new Error('Coverage dir lost to a concurrent run; use a unique reportsDirectory.')\n  }\n  throw e\n}","preventionTips":["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."],"tags":["coverage","v8","filesystem","concurrency"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}