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
Thrown by parseFilter() (code VITEST_RANGE_LOCATION_FILTER_PROVIDED) when a CLI/test filter contains a line range such as `file.test.ts:10-20`. Vitest location filters support a single exact line number (`file:42`) but not ranges; the parser detects the `\d+-\d+` pattern after the last colon and rejects it, suggesting exact line numbers instead.
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 d568f8ce37)
Solutions
- Specify a single exact line number: `vitest file.test.ts:10` (the test that starts at or covers that line runs).
- Run the whole file (`vitest file.test.ts`) and use test-name filters (`-t 'name'`) to narrow further.
- Update editor integrations to send a single line rather than a range.
Example fix
# before vitest src/utils.test.ts:10-20 # after vitest src/utils.test.ts:10
Defensive patterns
Strategy: validation
Validate before calling
function normalizeFilter(f: string): string {
// strip a trailing range, keep a single line number
return f.replace(/:(\d+)-\d+$/, ':$1')
} Type guard
function isRangeFilter(f: string): boolean {
const i = f.lastIndexOf(':')
if (i === -1) return false
return /^\d+-\d+$/.test(f.slice(i + 1))
} Try / catch
try {
startVitest(...)
} catch (e) {
if (e instanceof RangeLocationFilterProvidedError) {
// rewrite the range filter to its first line and retry
} else throw e
} Prevention
- Pass a single exact line number after the colon in file filters.
- Update editor integrations to send the cursor line, not a selection range.
- Validate user-supplied filters with the isRangeFilter guard before passing them to Vitest.
When it happens
Trigger: Passing `vitest path/to/file.test.ts:10-20` on the CLI or clicking a range in an IDE that forwards it as a filter. The regex `/^\d+-\d+$/` matches the post-colon segment and the error fires.
Common situations: IDE/editor integrations that construct range filters; users assuming range selection (like editor highlights) maps to test ranges; copying a `git blame`-style range.
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/b10dfa90b62efe71.json.
Report an issue: GitHub.