## TL;DR

Vitest found zero files matching its include patterns, so it exits 1 without running anything. The default include is narrower than people expect: it only matches test or spec suffixed files under the project root. Rename the files, fix the include pattern, or run from the right directory.

## Error

```text
Error: No test files found, exiting with code 1
```

## Steps

1. Confirm the file names: list your source dir and check each test file ends in `.test.ts`, `.test.js`, `.spec.ts`, or similar. Expected: files match the pattern; `utils.check.ts` does not.
2. If the names are right, check where you run from: run vitest from the directory containing vitest.config, not a subfolder. Expected: the config file sits in the current directory.
3. Check `test.include` in the config; the default is `['**/*.{test,spec}.?(c|m)[jt]s?(x)']`. Expected: your files fall under one of the include globs.
4. Check `test.exclude`: node_modules and dist are excluded by default, and a broad custom exclude can swallow your tests. Expected: removing the custom exclude makes the files appear.
5. Re-run with one file listed explicitly to confirm the runner works: `npx vitest run src/utils.test.ts`. Expected: the tests execute; then fix the include or the naming for the full run.

## When to use

- Vitest exits code 1 with zero tests run.
- It started after renaming files or moving the config.
- A monorepo package has no config of its own and inherits odd defaults.

## When not to use

- Tests run and fail (a test bug, not a discovery bug).
- `Cannot find module` (an import error inside a discovered file).
- Watch mode starts but finds nothing (same fix, plus check the `dir` option).

## Tool compatibility

- Vitest 0.30 through 3.x; Vite 4, 5, and 6 projects.

## Variant phrasings

### No test files found in CI only

The checkout layout or working directory differs from your laptop. Compare the two.

### after converting from Jest

Old spec files in `__tests__` directories are fine as long as the file names match the include pattern.

### with --run versus watch mode

Same include logic in both; the mode does not change discovery.

## Why it happens

Vitest globs the project for test files before starting; if nothing matches (wrong names, wrong working directory, an over-broad exclude, or an include pointing elsewhere), it exits 1 rather than running an empty suite silently.

## Edge cases

- A `test.include` with an absolute path breaks when the repo moves machines.
- `__tests__` directories are included only if the files inside match the naming pattern.
- A vitest workspace file can redirect projects away from your files; check it when the config looks right.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_05gatItqxD75dZCvwYYbVw
