vitest-dev/vitest · error · LocationFilterFileNotFoundError
VITEST_LOCATION_FILTER_FILE_NOT_FOUND
VITEST_LOCATION_FILTER_FILE_NOT_FOUND
Error message
Couldn't find file ${filename}. Note when specifying the test location you have to specify the full test filename. What it means
Thrown as `LocationFilterFileNotFoundError` (code `VITEST_LOCATION_FILTER_FILE_NOT_FOUND`) from `globTestSpecifications` (specifications.ts:86) when a location filter specifies a file that no project's test glob matched. After globbing test files for every project, Vitest checks each requested location file; if a requested file (with non-empty line filters) was never matched, it reports the filename so the user knows the path didn't resolve to a known test file.
Source
Thrown at packages/vitest/src/node/specifications.ts:86
testLocHasMatch[file] = true
const spec = project.createSpecification(file, lines)
this.ensureSpecificationCached(spec)
files.push(spec)
})
typecheckTestFiles.forEach((file) => {
const lines = testLines[file]
testLocHasMatch[file] = true
const spec = project.createSpecification(file, lines, 'typescript')
this.ensureSpecificationCached(spec)
files.push(spec)
})
}))
Object.entries(testLines).forEach(([filepath, loc]) => {
if (loc.length !== 0 && !testLocHasMatch[filepath]) {
throw new LocationFilterFileNotFoundError(
relative(dir, filepath),
)
}
})
return files
}
public clearCache(moduleId?: string): void {
if (moduleId) {
this._cachedSpecs.delete(moduleId)
}
else {
this._cachedSpecs.clear()
}
}
private getCachedSpecifications(moduleId: string): TestSpecification[] | undefined {View on GitHub (pinned to d568f8ce37)
Solutions
- Use the full, correct test filename relative to the cwd (or absolute).
- Check the project's `include`/`exclude` globs to confirm the file is treated as a test.
- Run from the directory the test path is relative to, or pass an absolute path.
- Ensure at least one enabled project's test glob matches the file.
Example fix
# before vitest src/wrong-name.test.ts:10 # after vitest src/utils/calc.test.ts:10
Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from 'node:fs'
import { resolve } from 'node:path'
const file = resolve(process.cwd(), userFilter.replace(/:\d+$/, ''))
if (!existsSync(file)) throw new Error(`Test file not found: ${file}`) Prevention
- Use absolute paths or run from the directory the relative test path is rooted at.
- Confirm the file matches at least one project's `include` glob.
- Double-check filenames for typos before running.
When it happens
Trigger: Passing `vitest ./src/foo.test.ts:5` where `foo.test.ts` is not under any project's `include` glob or is outside the project root; using a relative path that doesn't resolve against `process.cwd()`; a typo in the test filename; the file exists but isn't considered a test file by any project.
Common situations: Wrong working directory; `include` pattern excludes the file; filename typo; referencing a file that lives in a different project not enabled in this run.
Related errors
- VITEST_INCLUDE_TASK_LOCATION_DISABLED
- Couldn't write file to fs
- Tester HTML file "${testerHtmlPath}" doesn't exist.
- Access denied to "${path}". See Vite config documentation fo
- Snapshot file "${id}" does not exist.
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/472b1db1cc73eb93.json.
Report an issue: GitHub.