{"id":"1ba3538c38c457ba","repo":"vitest-dev/vitest","slug":"snapshot-file-id-does-not-exist","errorCode":null,"errorMessage":"Snapshot file \"${id}\" does not exist.","messagePattern":"Snapshot file \"(.+?)\" does not exist\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser/src/node/rpc.ts","lineNumber":299,"sourceCode":"          if (!canWrite(project)) {\n            vitest.logger.error(\n              `[vitest] Cannot save snapshot file \"${id}\". File writing is disabled because server is exposed to the internet, see https://vitest.dev/config/api.`,\n            )\n            return\n          }\n          await fs.mkdir(dirname(id), { recursive: true })\n          await fs.writeFile(id, content, 'utf-8')\n        },\n        async removeSnapshotFile(id) {\n          checkFileAccess(id)\n          if (!canWrite(project)) {\n            vitest.logger.error(\n              `[vitest] Cannot remove snapshot file \"${id}\". File writing is disabled because server is exposed to the internet, see https://vitest.dev/config/api.`,\n            )\n            return\n          }\n          if (!existsSync(id)) {\n            throw new Error(`Snapshot file \"${id}\" does not exist.`)\n          }\n          await fs.unlink(id)\n        },\n        getBrowserFileSourceMap(id) {\n          const mod = globalServer.vite.moduleGraph.getModuleById(id)\n          const result = mod?.transformResult\n          // handle non-inline source map such as pre-bundled deps in node_modules/.vite\n          if (result && !result.map) {\n            const filePath = id.split('?')[0]\n            const extracted = extractSourcemapFromFile(result.code, filePath)\n            return extracted?.map\n          }\n          return result?.map\n        },\n        cancelCurrentRun(reason) {\n          vitest.cancelCurrentRun(reason)\n        },\n        async resolveId(id, importer) {","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/browser/src/node/rpc.ts#L281-L317","documentation":"`removeSnapshotFile` runs `existsSync(id)` before `fs.unlink`. If the snapshot was never created, already deleted, or removed by another concurrent process, the unlink would throw `ENOENT`; Vitest surfaces a clearer message naming the missing file.","triggerScenarios":"The orchestrator calls `removeSnapshotFile` (e.g. during `--clean`/snapshot cleanup, or `--update` discarding obsolete snapshots) for a file path that isn't on disk.","commonSituations":"Parallel test workers racing to clean the same snapshot; running `--clean` after already-deleting snapshots manually; CI caching that strips snapshot files between runs.","solutions":["Run snapshot cleanup serially if multiple workers share a snapshot file (e.g. `--no-file-parallelism` or `pool: 'forks'` with single fork).","Avoid manually deleting snapshot files while tests run.","Re-run with `--update` to regenerate snapshots before cleanup."],"exampleFix":"// before — manual cleanup racing with vitest\nfs.unlinkSync(snapshotPath)\n\n// after — let vitest manage snapshots; run cleanup once\nvitest run --update  // then vitest run --clean","handlingStrategy":"validation","validationCode":"import { existsSync } from 'node:fs'\n\nfunction assertSnapshotExists(path: string): void {\n  if (!existsSync(path)) {\n    throw new Error(`Refusing to remove missing snapshot: ${path}`)\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await fs.unlink(snapshotPath)\n} catch (err) {\n  if ((err as NodeJS.ErrnoException).code === 'ENOENT') return // already gone\n  throw err\n}","preventionTips":["Don't manually delete snapshots while vitest manages them.","Run snapshot cleanup serially when workers share files.","Regenerate snapshots with --update before --clean."],"tags":["snapshot","filesystem","cleanup"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}