jestjs/jest · error · Error
Can't find a root directory while resolving a config file pa
Error message
Can't find a root directory while resolving a config file path.
Provided path to resolve: ${pathToResolve}
cwd: ${cwd} What it means
resolveConfigPath first checks if the resolved path is a file; if not, it checks existence. If the path does not exist on disk at all (neither file nor directory), it throws this guard error. This prevents a non-existent project/config path from accidentally resolving to a parent directory's package.json and running unrelated tests.
Source
Thrown at packages/jest-config/src/resolveConfigPath.ts:52
? pathToResolve
: path.resolve(cwd, pathToResolve);
if (isFile(absolutePath)) {
return absolutePath;
}
// This is a guard against passing non existing path as a project/config,
// that will otherwise result in a very confusing situation.
// e.g.
// With a directory structure like this:
// my_project/
// package.json
//
// Passing a `my_project/some_directory_that_doesnt_exist` as a project
// name will resolve into a (possibly empty) `my_project/package.json` and
// try to run all tests it finds under `my_project` directory.
if (!fs.existsSync(absolutePath)) {
throw new Error(
"Can't find a root directory while resolving a config file path.\n" +
`Provided path to resolve: ${pathToResolve}\n` +
`cwd: ${cwd}`,
);
}
return resolveConfigPathByTraversing(
absolutePath,
pathToResolve,
cwd,
skipMultipleConfigError,
);
}
const resolveConfigPathByTraversing = (
pathToResolve: string,
initialPath: string,
cwd: string,View on GitHub (pinned to f49721c78e)
Solutions
- Verify the path exists: list the file or directory you passed
- Correct typos in the --config argument or project path
- Run jest from the directory containing the config if using a relative path
Example fix
// before jest --config ./jest.confug.js // typo // after jest --config ./jest.config.js
Defensive patterns
Strategy: validation
Validate before calling
import * as fs from 'node:fs';
import * as path from 'node:path';
const abs = path.isAbsolute(p) ? p : path.resolve(cwd, p);
if (!fs.existsSync(abs)) {
throw new Error(`Path does not exist: ${abs}`);
} Prevention
- Validate --config paths in CI before the test step
- Use absolute config paths in CI to avoid cwd drift
When it happens
Trigger: Running `jest --config ./missing.config.js` or `jest ./nonexistent-dir` where the path resolves to something that does not exist.
Common situations: Typo in the --config path; running jest from the wrong working directory; deleted/moved config files after a refactor.
Related errors
- "cwd" must be an absolute path. cwd: ${cwd}
- Multiple configurations found Implicit config resolution d
- Could not find a config file based on provided values: path:
- Filter ${filterPath} did not return a valid test list
- The --config option requires a JSON string literal, or a fil
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/d4c40b3a9e3429c8.json.
Report an issue: GitHub.