vitest-dev/vitest · error · Error
Snapshot file "${id}" does not exist.
Error message
Snapshot file "${id}" does not exist. What it means
`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.
Source
Thrown at packages/browser/src/node/rpc.ts:299
if (!canWrite(project)) {
vitest.logger.error(
`[vitest] Cannot save snapshot file "${id}". File writing is disabled because server is exposed to the internet, see https://vitest.dev/config/api.`,
)
return
}
await fs.mkdir(dirname(id), { recursive: true })
await fs.writeFile(id, content, 'utf-8')
},
async removeSnapshotFile(id) {
checkFileAccess(id)
if (!canWrite(project)) {
vitest.logger.error(
`[vitest] Cannot remove snapshot file "${id}". File writing is disabled because server is exposed to the internet, see https://vitest.dev/config/api.`,
)
return
}
if (!existsSync(id)) {
throw new Error(`Snapshot file "${id}" does not exist.`)
}
await fs.unlink(id)
},
getBrowserFileSourceMap(id) {
const mod = globalServer.vite.moduleGraph.getModuleById(id)
const result = mod?.transformResult
// handle non-inline source map such as pre-bundled deps in node_modules/.vite
if (result && !result.map) {
const filePath = id.split('?')[0]
const extracted = extractSourcemapFromFile(result.code, filePath)
return extracted?.map
}
return result?.map
},
cancelCurrentRun(reason) {
vitest.cancelCurrentRun(reason)
},
async resolveId(id, importer) {View on GitHub (pinned to d568f8ce37)
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.
Example fix
// before — manual cleanup racing with vitest fs.unlinkSync(snapshotPath) // after — let vitest manage snapshots; run cleanup once vitest run --update // then vitest run --clean
Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from 'node:fs'
function assertSnapshotExists(path: string): void {
if (!existsSync(path)) {
throw new Error(`Refusing to remove missing snapshot: ${path}`)
}
} Try / catch
try {
await fs.unlink(snapshotPath)
} catch (err) {
if ((err as NodeJS.ErrnoException).code === 'ENOENT') return // already gone
throw err
} Prevention
- Don't manually delete snapshots while vitest manages them.
- Run snapshot cleanup serially when workers share files.
- Regenerate snapshots with --update before --clean.
When it happens
Trigger: The orchestrator calls `removeSnapshotFile` (e.g. during `--clean`/snapshot cleanup, or `--update` discarding obsolete snapshots) for a file path that isn't on disk.
Common situations: Parallel test workers racing to clean the same snapshot; running `--clean` after already-deleting snapshots manually; CI caching that strips snapshot files between runs.
Related errors
- Access denied to "${path}". See Vite config documentation fo
- cannot read ${file} when saving inline snapshot
- provider ${context.provider.name} is not supported
- aria adapter expects an Element
- Couldn't write file to fs
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/1ba3538c38c457ba.json.
Report an issue: GitHub.