vitest-dev/vitest · error · RangeLocationFilterProvidedError
VITEST_RANGE_LOCATION_FILTER_PROVIDED
VITEST_RANGE_LOCATION_FILTER_PROVIDED
Error message
Found "-" in location filter ${filter}. Note that range location filters are not supported. Consider specifying the exact line numbers of your tests. What it means
`parseFilter` accepts a `filename:line` form but rejects `filename:start-end` ranges — range location filters are not supported. When the segment after the last colon matches `^\d+-\d+$`, it throws a `RangeLocationFilterProvidedError` (code `VITEST_RANGE_LOCATION_FILTER_PROVIDED`). The user is asked to specify exact line numbers instead.
Solutions
- Pass a single exact line: `vitest src/foo.test.ts:10` (the test that starts on line 10).
- Run the file without a line filter to execute the whole suite: `vitest src/foo.test.ts`.
- If you need to run several tests, pass multiple `:line` filters as separate argv entries.
Example fix
# before vitest src/foo.test.ts:10-20 # after vitest src/foo.test.ts:10
Defensive patterns
Strategy: validation
Validate before calling
function normalizeLocationFilter(filter: string): string {
// strip a `start-end` range down to its start line
return filter.replace(/:(\d+)-\d+$/, ':$1')
}
const safe = normalizeLocationFilter(userFilter) Prevention
- Pass a single `:line` to target a specific test by its declaration line.
- If an editor hands you a range, take the first number before the dash.
- Drop the line filter to run the whole file when unsure.
When it happens
Trigger: Passing `vitest src/foo.test.ts:10-20`, `vitest foo.test.ts:5-5`, or any location filter whose numeric part contains a hyphen. The same path through `parseFilter` is used by CLI argv and editor integrations.
Common situations: Copy-pasting a range from an IDE selection; assuming Vitest mirrors Jest's `:line` filter but extends it to ranges; a VS Code extension passing the selected line range.
Related errors
- No projects were found. Make sure your configuration is…
- VITEST_INCLUDE_TASK_LOCATION_DISABLED
- VITEST_LOCATION_FILTER_FILE_NOT_FOUND
- "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/b10dfa90b62efe71.
Report an issue: GitHub.
Appendix: source
Thrown at packages/vitest/src/node/cli/filter.ts:22
export function parseFilter(filter: string): FileFilter {
const colonIndex = filter.lastIndexOf(':')
if (colonIndex === -1) {
return { filename: filter }
}
const [parsedFilename, lineNumber] = [
filter.substring(0, colonIndex),
filter.substring(colonIndex + 1),
]
if (/^\d+$/.test(lineNumber)) {
return {
filename: parsedFilename,
lineNumber: Number.parseInt(lineNumber),
}
}
else if (/^\d+-\d+$/.test(lineNumber)) {
throw new RangeLocationFilterProvidedError(filter)
}
else {
return { filename: filter }
}
}
export interface FileFilter {
filename: string
lineNumber?: undefined | number
}
export function groupFilters(filters: FileFilter[]): Record<string, number[]> {
const groupedFilters_ = groupBy(filters, f => f.filename)
const groupedFilters = Object.fromEntries(Object.entries(groupedFilters_)
.map((entry) => {
const [filename, filters] = entry
const testLocations = filters.map(f => f.lineNumber)
View on GitHub (pinned to 1fa9837ec2)