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

  1. Use the full, exact test filename as it appears in Vitest's normal output.
  2. Confirm the file is matched by some project's `include` glob (run without the `:line` filter to see it discovered).
  3. 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

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


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)