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.map(ext => `"${getConfigFilename(ext)}"`).join(' or ')}. What it means
If tree traversal reaches the filesystem root without finding any jest.config.* file or a package.json with a jest key, this error is thrown listing the searched extensions in order. It tells the user what filenames Jest looks for and that either a direct file path or a directory (searched upward) is required.
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 f49721c78e)
Solutions
- Create a jest.config.js (or any supported extension) in the project root
- Run jest from a directory that contains or is beneath a config file
- Pass --config <absolute path> to point at an existing config
- Add a jest key to package.json
Example fix
// before: no config present
npx jest
// after: create jest.config.js
export default {testEnvironment: 'node'}; Defensive patterns
Strategy: validation
Validate before calling
import * as fs from 'node:fs';
import * as path from 'node:path';
function findConfigUp(dir: string): string | undefined {
const exts = ['.js','.ts','.mjs','.mts','.cjs','.cts','.json'];
let cur = dir;
while (true) {
const hit = exts.map(e => path.join(cur, 'jest.config'+e)).find(fs.existsSync);
if (hit) return hit;
const parent = path.dirname(cur);
if (parent === cur) return undefined;
cur = parent;
}
}
if (!findConfigUp(process.cwd())) throw new Error('No jest config found'); Prevention
- Add a config as part of project scaffolding
- Pin --config in CI scripts
- Run jest from the project root
When it happens
Trigger: Running jest in a directory with no config and no ancestor config; passing a project path that is outside any configured Jest project.
Common situations: Fresh project without a config; running jest from /tmp or a scratch dir; wrong cwd in CI; monorepo where a package lacks its own config and the root config lives elsewhere.
Related errors
- Can't find a root directory while resolving a config file pa
- Multiple configurations found Implicit config resolution d
- Filter ${filterPath} did not return a valid test list
- The --config option requires a JSON string literal, or a fil
- Cannot merge config in form of callback
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/2ce8bf04661b3732.json.
Report an issue: GitHub.