vitest-dev/vitest · error · FilesNotFoundError
VITEST_FILES_NOT_FOUND
VITEST_FILES_NOT_FOUND
Error message
No test files found
What it means
FilesNotFoundError (code VITEST_FILES_NOT_FOUND) is thrown when no test specifications are produced and the run is not a watch-with-changed/related trigger. It is Vitest's canonical 'no test files found' error: nothing matched the include/glob/filter inputs. Suppressed only in watch mode when --changed or --related is also set.
Solutions
- Check config.include actually matches files: list the resolved globs.
- Verify --root / current working directory is the project root.
- Remove overly restrictive CLI filters (e.g. a misspelled path).
- Pass --pass-with-no-tests (or set passWithNoTests: true) if an empty run is acceptable.
- If using --watch with --changed/--related, that path suppresses the throw legitimately.
Example fix
// before - config with overly narrow include
export default defineConfig({ test: { include: ['src/**/*.spec.ts'] } })
// after
export default defineConfig({
test: { include: ['test/**/*.test.ts', 'src/**/*.spec.ts'] }
}) Defensive patterns
Strategy: validation
Validate before calling
import { glob } from 'tinyglobby'
async function hasMatchedTests(config) {
const files = await glob(config.include, { cwd: config.root, ignore: config.exclude })
return files.length > 0
}
// before run: if (!await hasMatchedTests(config)) set passWithNoTests or fix globs Try / catch
try {
await vitest.start()
} catch (e) {
if (e.code === 'VITEST_FILES_NOT_FOUND') {
// log, fix include/root, or set passWithNoTests and retry
} else throw e
} Prevention
- Set passWithNoTests: true when an empty run is acceptable (e.g. filtered CI jobs).
- Validate include globs against the actual test directory before running.
- Confirm --root / cwd; run with --no-color --reporter=verbose to see resolved patterns.
When it happens
Trigger: Running Vitest where specifications.length === 0 AND not (config.watch && (config.changed || config.related?.length)). Caused by include globs matching zero files, wrong --root/cwd, or CLI file filters that match nothing.
Common situations: Wrong working directory; glob excludes everything; renamed test files; a typo'd filter arg; fresh repo with no tests; CI running in a subdirectory.
Related errors
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/8650131dd6757c04.
Report an issue: GitHub.
Appendix: source
Thrown at packages/vitest/src/node/core.ts:866
specifications = specifications.filter(({ testModule }) => {
return !testModule || testModule.task.mode !== 'skip'
})
}
// if run with --changed, don't exit if no tests are found
if (!specifications.length) {
await this._traces.$('vitest.test_run', async () => {
await this._testRun.start([])
await this.coverageProvider?.onTestRunStart?.()
const coverage = await this.coverageProvider?.generateCoverage?.({ allTestsRun: true })
await this._testRun.end([], [], coverage)
// Report coverage for uncovered files
await this.reportCoverage(coverage, true)
})
if (!this.config.watch || !(this.config.changed || this.config.related?.length)) {
throw new FilesNotFoundError()
}
}
let testModules: TestRunResult = {
testModules: [],
unhandledErrors: [],
}
if (specifications.length) {
// populate once, update cache on watch
await this.cache.stats.populateStats(this.config.root, specifications)
testModules = await this.runFiles(specifications, true)
}
if (this.config.watch) {
await this.report('onWatcherStart')
}View on GitHub (pinned to 1fa9837ec2)