Why running vitest from a subdirectory stops finding config
Vitest 4 walked up the directory tree looking for a config file if the current working directory didn’t have one. That made a certain style of monorepo or CI script “just work”: cd packages/api && vitest would pick up a vitest.config.ts sitting at the repo root, even though nothing in that subdirectory pointed at it.
Vitest’s own migration guide states the change plainly, in the section covering config file lookup:
Vitest no longer searches parent directories for config files. If you previously relied on running
vitestfrom a subdirectory while using a config file from a parent directory, pass the config explicitly and scope test discovery with--dir.
The guide’s own example shows exactly what changes:
$ cd subdir && vitest$ cd subdir && vitest --config ../vitest.config.tsThe command that used to resolve config by walking upward now just doesn’t find one, because that walk no longer happens. Whatever Vitest does when no config file is found (fall back to defaults, or fail outright) depends on the rest of your setup, but either way it isn’t running with the config you meant it to use.
This is a workflow break, not a config-syntax error
Nothing about your vitest.config.ts file changes here. The file is correct
and untouched. What breaks is the working directory a command gets run from,
which makes this the kind of failure that’s easy to miss in a code review,
since the diff that breaks it is often in a CI YAML file or a package.json
script, not in the test config itself.
Fix it: pass the config path (and scope) explicitly
Option 1: pass —config directly
The direct fix, matching the guide’s own example. Point the command at the config file explicitly instead of hoping it gets found:
{
"scripts": {
"test": "cd packages/api && vitest"
}
}{
"scripts": {
"test": "cd packages/api && vitest --config ../../vitest.config.ts --dir ."
}
}--dir scopes which directory Vitest treats as the root for discovering test files, which matters once you’re pointing --config somewhere outside the current directory. Confirm the exact --dir semantics against Vitest’s own CLI reference for your version before copying this into a script wholesale, since flag behavior can shift between beta releases faster than stable config surface does.
Option 2: give the subdirectory its own config file
If the subdirectory’s tests don’t genuinely need to share every setting from the parent config, moving (or adding) a vitest.config.ts directly in that directory sidesteps the whole issue. Vitest still checks the current working directory by default; only the upward search into parent directories is gone. A config file sitting right next to the code it tests never depended on that search in the first place.
Confirmed version range
Documented in Vitest’s own current migration guide as an intentional Vitest 5.0 change, in the section covering config file lookup. This repository’s own vitest.config.ts is pinned to vitest@^3.0.0, so this behavior wasn’t independently reproduced against this project’s build; every claim above traces back to Vitest’s migration guide, not a local repro.
More fixes like this one are in the Guides & Fixes archive, and every Vitest post is tagged under vitest. If your upgrade is also hitting removed test options, see Fix Vitest 5 test.sequential Removed Error.







