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
A location (line-number) filter references a file that no project's test globs include. Vitest validates this after globbing so a typo'd filename with a `:line` filter doesn't silently run nothing. The path must be the full test filename as resolved from `process.cwd()`.
Solutions
- Use the full, exact test filename as it appears in Vitest's normal output.
- Confirm the file is matched by some project's `include` glob (run without the `:line` filter to see it discovered).
- Run from the same working directory Vitest resolves filters against (`process.cwd()`).
Example fix
# before: file path is relative to a different cwd / not matched vitest foo.test.ts:10 # VITEST_LOCATION_FILTER_FILE_NOT_FOUND # after: use the full path as shown in vitest output vitest tests/unit/foo.test.ts:10
Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from 'node:fs'
import { resolve } from 'node:path'
function assertLocationFilterFileExists(cwd: string, filters: string[]) {
for (const f of filters) {
const m = f.match(/^(.*):\d+$/)
if (!m) continue
const file = resolve(cwd, m[1])
if (!existsSync(file)) {
throw new Error(`Location filter file not found: ${m[1]} (resolved to ${file}). Use the full test path.`)
}
}
} Prevention
- Use absolute or cwd-relative test paths exactly as Vitest prints them.
- Run the file without the `:line` filter first to confirm it is discovered.
When it happens
Trigger: `vitest tests/foo.test.ts:10` where `tests/foo.test.ts` is not in any project's `testFiles`/`typecheckTestFiles`; the entry in `testLines` has no matching `testLocHasMatch`.
Common situations: Relative-path mismatch (cwd vs. root); file renamed; pointing at a source file instead of the test file; the file isn't covered by any project's `include` glob.
Related errors
- No projects were found. Make sure your configuration is…
- VITEST_INCLUDE_TASK_LOCATION_DISABLED
- VITEST_RANGE_LOCATION_FILTER_PROVIDED
- "browser.instances" was set in the config, but the array is…
- --cache.dir is deprecated
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/472b1db1cc73eb93.
Report an issue: GitHub.
Appendix: source
Thrown at packages/vitest/src/node/specifications.ts:87
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 1fa9837ec2)