vitest-dev/vitest · warning · Error
Snapshot file " " does not exist.
Error message
Snapshot file "${id}" does not exist. What it means
removeSnapshotFile checks existsSync(id) before calling fs.unlink and throws if the file is absent. The guard prevents an ENOENT from unlink, surfacing a clearer message. It runs after checkFileAccess and the canWrite guard, so it indicates the file was simply not there to remove.
Solutions
- Check existence before requesting removal, or catch the error and treat it as a no-op.
- Verify the id passed matches an actual on-disk snapshot path.
- Avoid running concurrent snapshot cleanups that race on the same file.
Example fix
// before
await rpc.removeSnapshotFile(id) // throws if absent
// after
import { existsSync } from 'node:fs'
if (existsSync(id)) await rpc.removeSnapshotFile(id) Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from 'node:fs'
function snapshotExists(id: string): boolean { return existsSync(id) } Try / catch
try { await rpc.removeSnapshotFile(id) }
catch (e) {
if (e instanceof Error && e.message.includes('does not exist')) return // idempotent
throw e
} Prevention
- Guard removal calls with existsSync when callers may invoke them more than once.
- Make cleanup tooling idempotent by catching the not-exist error.
- Avoid concurrent cleanups on the same snapshot path.
When it happens
Trigger: Calling the removeSnapshotFile RPC (typically via snapshot cleanup tooling) with a path to a snapshot that was already deleted, never written, or whose name differs from what was passed.
Common situations: Running snapshot cleanup twice; passing a snapshot id with a different extension (.snap vs the file path); a previous test run that failed before writing the snapshot; manual deletion of the snapshot file between operations.
Related errors
- Access denied to " ". See Vite config documentation for…
- aria adapter expects an Element
- cannot read when saving inline snapshot
- Couldn't write file to fs
- provider is not supported
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/1ba3538c38c457ba.
Report an issue: GitHub.
Appendix: 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 1fa9837ec2)