{"record":{"id":"cdbe1c11de22de82","repo":"vitest-dev/vitest","slug":"something-removed-the-coverage-directory-covera","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-istanbul/src/commands.ts","lineNumber":28,"sourceCode":"    const provider = context.project.vitest.coverageProvider as IstanbulCoverageProvider\n\n    return writeCoverageFile(provider.coverageFilesDirectory, coverage)\n  },\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","sourceCodeStart":10,"sourceCodeEnd":39,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/coverage-istanbul/src/commands.ts#L10-L39","documentation":"Thrown by writeCoverageFile (istanbul provider) when writeFile fails and existsSync reports the coverage directory it created earlier is now gone. The intended diagnosis is concurrency: another process wiped or reused the same reportsDirectory mid-run.","triggerScenarios":"writeCoverageFile(coverageFilesDirectory, coverage) calls writeFile, the call throws, and a subsequent existsSync(coverageFilesDirectory) returns false — meaning the directory was removed between setup and write.","commonSituations":"Two Vitest processes (e.g. unit and e2e) configured with the same coverage.reportsDirectory; a watch-mode rerun colliding with a clean script; CI that deletes the coverage folder between shards; an external tool (rm -rf coverage) racing the test.","solutions":["Give each concurrent Vitest run a distinct coverage.reportsDirectory (e.g. coverage-unit, coverage-e2e) or run them sequentially.","Remove pre-run clean hooks that delete the coverage dir; clean before the run starts, not during.","In CI shards, namespace the reportsDirectory per shard and merge after."],"exampleFix":"// before: two projects share the same dir\nexport default defineConfig({ test: { coverage: { reportsDirectory: './coverage' } } })\n// after\nexport default defineConfig({ test: { coverage: { reportsDirectory: './coverage/unit' } } })","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    // a concurrent run wiped the dir — re-run isolated, or merge later\n    throw new Error('Coverage dir lost to a concurrent run; use a unique reportsDirectory.')\n  }\n  throw e\n}","preventionTips":["Give every concurrent Vitest run its own coverage.reportsDirectory.","Run coverage clean hooks before the run, never during.","In CI shards, namespace reportsDirectory per shard and merge after."],"tags":["coverage","istanbul","filesystem","concurrency"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}