{"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/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/coverage-istanbul/src/commands.ts#L10-L39","documentation":"Thrown by the Istanbul coverage provider's writeCoverageFile when writeFile fails AND the coverage directory no longer exists. The directory is created earlier in the run; its disappearance mid-run signals an external process (typically a concurrent Vitest) deleted it.","triggerScenarios":"Browser-mode coverage writes a coverage-<uuid>.json into coverageFilesDirectory; the write throws ENOENT and existsSync(coverageFilesDirectory) is false, triggering this wrapper error with the original as cause.","commonSituations":"Two Vitest processes sharing the same coverage.reportsDirectory (e.g. unit + browser CI jobs in parallel); a watch/clean step or coverage-cleaning script racing with the run; running coverage in a container whose tmp dir is reaped.","solutions":["Give each concurrent Vitest run a distinct coverage.reportsDirectory.","Run coverage jobs sequentially instead of in parallel.","Remove any script/watcher that deletes the reports directory during the run."],"exampleFix":"// before — two jobs share the default 'coverage/'\n// job A: vitest --coverage\n// job B: vitest --coverage (browser)\n// after\n// job A: vitest --coverage --coverage.reportsDirectory=coverage/unit\n// job B: vitest --coverage --coverage.reportsDirectory=coverage/browser","handlingStrategy":"validation","validationCode":"import { existsSync, mkdirSync } from 'node:fs'\n// ensure reportsDirectory exists right before writing\nif (!existsSync(coverageFilesDirectory)) {\n  mkdirSync(coverageFilesDirectory, { recursive: true })\n}","typeGuard":null,"tryCatchPattern":"try {\n  await writeCoverageFile(dir, coverage)\n} catch (e) {\n  if (/removed the coverage directory/i.test(String((e as Error).message))) {\n    // retry once after recreating the dir\n    mkdirSync(dir, { recursive: true })\n    return writeCoverageFile(dir, coverage)\n  }\n  throw e\n}","preventionTips":["Use a distinct coverage.reportsDirectory per concurrent Vitest process.","Don't clean coverage/ mid-run; clean it in a pre-run step only.","Run coverage-generating jobs sequentially in CI."],"tags":["coverage","istanbul","filesystem","concurrency"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}