vitest-dev/vitest · error · IncludeTaskLocationDisabledError
VITEST_INCLUDE_TASK_LOCATION_DISABLED
VITEST_INCLUDE_TASK_LOCATION_DISABLED
Error message
Received line number filters while `includeTaskLocation` option is disabled
What it means
Line-number location filters (e.g. `vitest foo.test.ts:42`) require Vitest to have recorded each test's source location at collection time, which only happens when `includeTaskLocation: true`. Passing a `file:line` filter while the option is off throws `IncludeTaskLocationDisabledError` so the filter isn't silently ignored.
Solutions
- Enable `includeTaskLocation: true` in the Vitest config (it has a small collection-time cost).
- Or drop the `:lineNumber` suffix and run the whole file instead.
- For programmatic use, gate line filters on the config value before passing them.
Example fix
// before
export default defineConfig({ test: {} })
// vitest foo.test.ts:10 -> VITEST_INCLUDE_TASK_LOCATION_DISABLED
// after
export default defineConfig({
test: { includeTaskLocation: true },
})
// vitest foo.test.ts:10 -> runs only the test at line 10 Defensive patterns
Strategy: validation
Validate before calling
function assertLineFiltersAllowed(config: { includeTaskLocation?: boolean }, filters: string[]) {
const hasLine = filters.some(f => /:\d+$/.test(f))
if (hasLine && !config.includeTaskLocation) {
throw new Error('Line filters require includeTaskLocation: true. Enable it or drop the :line suffix.')
}
} Prevention
- Set `includeTaskLocation: true` in any config where you intend to use `file:line` filters.
- Strip `:line` suffixes programmatically when the option is off.
When it happens
Trigger: Any filter parsed by `parseFilter` that yields `lineNumber !== undefined`, while `vitest.config.includeTaskLocation` is falsy. Triggered via CLI (`file:line`) or programmatic filters passed to `globTestSpecifications`.
Common situations: New users trying `vitest foo.test.ts:10` with default config; programmatic API passing `{ filename, lineNumber }` filters; migration from a tool where line filters work by default.
Related errors
- No projects were found. Make sure your configuration is…
- "browser.instances" was set in the config, but the array is…
- --cache.dir is deprecated
- Inspector host cannot be a URL. Use "host:port" instead of
- No projects matched the filter
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/fcdf47c3377d43e8.
Report an issue: GitHub.
Appendix: source
Thrown at packages/vitest/src/node/specifications.ts:52
}
public async getRelevantTestSpecifications(filters: string[] = []): Promise<TestSpecification[]> {
return this.filterTestsBySource(
await this.globTestSpecifications(filters),
)
}
public async globTestSpecifications(filters: string[] = []): Promise<TestSpecification[]> {
const files: TestSpecification[] = []
const dir = process.cwd()
const parsedFilters = filters.map(f => parseFilter(f))
// Require includeTaskLocation when a location filter is passed
if (
!this.vitest.config.includeTaskLocation
&& parsedFilters.some(f => f.lineNumber !== undefined)
) {
throw new IncludeTaskLocationDisabledError()
}
const testLines = groupFilters(parsedFilters.map(
f => ({ ...f, filename: resolve(dir, f.filename) }),
))
// Key is file and val specifies whether we have matched this file with testLocation
const testLocHasMatch: { [f: string]: boolean } = {}
await Promise.all(this.vitest.projects.map(async (project) => {
const { testFiles, typecheckTestFiles } = await project.globTestFiles(
parsedFilters.map(f => f.filename),
)
testFiles.forEach((file) => {
const lines = testLines[file]
testLocHasMatch[file] = true
View on GitHub (pinned to 1fa9837ec2)