jestjs/jest · error · Error
Could not find a config file based on provided values: path
Error message
Could not find a config file based on provided values:
path: "${initialPath}"
cwd: "${cwd}"
Config paths must be specified by either a direct path to a config
file, or a path to a directory. If directory is given, Jest will try to
traverse directory tree up, until it finds one of those files in exact order: ${JEST_CONFIG_EXT_ORDER}. What it means
Thrown via makeResolutionErrorMessage when directory traversal reaches the filesystem root without finding any Jest config file or a package.json with a 'jest' key. The message lists JEST_CONFIG_EXT_ORDER so the user knows which filenames would have been accepted.
Solutions
- Create a jest.config.js (or another supported extension) in the project root
- Or add a "jest": {} key to package.json
- Confirm you are running jest from the intended project directory (pwd)
- Pass --config <absolute-path> to point Jest at a config elsewhere
Example fix
// before: no config anywhere
jest
// -> Could not find a config file...
// after: create jest.config.js
/** @type {import('jest').Config} */
module.exports = { testEnvironment: 'node' }; Defensive patterns
Strategy: validation
Validate before calling
import * as fs from 'node:fs';
import * as path from 'node:path';
function assertConfigDiscoverable(dir: string): void {
let current = path.resolve(dir);
while (true) {
const hasConfig = ['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs', '.json']
.some(ext => fs.existsSync(path.join(current, `jest.config${ext}`)));
const pkg = path.join(current, 'package.json');
const hasPkgJest = fs.existsSync(pkg) && JSON.parse(fs.readFileSync(pkg, 'utf8')).jest;
if (hasConfig || hasPkgJest) return;
const parent = path.dirname(current);
if (parent === current) {
throw new Error(`No Jest config found from ${dir} up to filesystem root`);
}
current = parent;
}
} Prevention
- Always create a jest.config.* when scaffolding a new project
- Run jest from the project root directory
- Pass --config explicitly in CI to avoid directory-dependent discovery
When it happens
Trigger: Running jest in a directory (or with a cwd) that has no jest.config.* file and no 'jest' key in any ancestor's package.json all the way up to '/'.
Common situations: Running jest from the wrong directory (e.g. /tmp or home); fresh projects that never created a config; CI that cd's into the wrong workspace; deleting the config accidentally.
Related errors
- Can't find a root directory while resolving a config file…
- ● Multiple configurations found: *
- ● Validation Error: Configuration in
- Crawler retry failed: Original error
- "cwd" must be an absolute path. cwd
AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10).
Data as JSON: /api/errors/1b78ed269152ed76.
Report an issue: GitHub.
Appendix: source
Thrown at packages/jest-config/src/resolveConfigPath.ts:118
configFiles.push(absolutePath);
} else {
configFiles.push(packageJson);
}
}
}
if (!skipMultipleConfigError && configFiles.length > 1) {
throw new ValidationError(...makeMultipleConfigsErrorMessage(configFiles));
}
if (configFiles.length > 0 || packageJson) {
return configFiles[0] ?? packageJson;
}
// This is the system root.
// We tried everything, config is nowhere to be found ¯\_(ツ)_/¯
if (pathToResolve === path.dirname(pathToResolve)) {
throw new Error(makeResolutionErrorMessage(initialPath, cwd));
}
// go up a level and try it again
return resolveConfigPathByTraversing(
path.dirname(pathToResolve),
initialPath,
cwd,
skipMultipleConfigError,
);
};
const findPackageJson = (pathToResolve: string) => {
const packagePath = path.resolve(pathToResolve, PACKAGE_JSON);
if (isFile(packagePath)) {
return packagePath;
}
return undefined;View on GitHub (pinned to 8e6d128e4a)