jestjs/jest · error · Error
"cwd" must be an absolute path. cwd: ${cwd}
Error message
"cwd" must be an absolute path. cwd: ${cwd} What it means
resolveConfigPath requires its `cwd` argument to be an absolute path because it resolves the user-supplied path relative to it. A relative cwd would produce wrong absolute paths and silently misresolve configs, so it is rejected up front. This is an internal/programmatic invariant - the CLI always passes an absolute cwd.
Source
Thrown at packages/jest-config/src/resolveConfigPath.ts:31
import {
JEST_CONFIG_BASE_NAME,
JEST_CONFIG_EXT_ORDER,
PACKAGE_JSON,
} from './constants';
import {BULLET, DOCUMENTATION_NOTE} from './utils';
const isFile = (filePath: string) =>
fs.existsSync(filePath) && !fs.lstatSync(filePath).isDirectory();
const getConfigFilename = (ext: string) => JEST_CONFIG_BASE_NAME + ext;
export default function resolveConfigPath(
pathToResolve: string,
cwd: string,
skipMultipleConfigError = false,
): string {
if (!path.isAbsolute(cwd)) {
throw new Error(`"cwd" must be an absolute path. cwd: ${cwd}`);
}
const absolutePath = path.isAbsolute(pathToResolve)
? 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` andView on GitHub (pinned to f49721c78e)
Solutions
- Pass an absolute cwd, typically process.cwd() or path.resolve(process.cwd())
- Use path.resolve() on any relative directory before passing it as cwd
Example fix
// before
resolveConfigPath(configFile, './packages/app')
// after
resolveConfigPath(configFile, path.resolve('packages/app')) Defensive patterns
Strategy: validation
Validate before calling
import * as path from 'node:path';
if (!path.isAbsolute(cwd)) {
cwd = path.resolve(cwd);
} Type guard
import * as path from 'node:path';
function isAbsolutePath(p: string): boolean {
return path.isAbsolute(p);
} Prevention
- Always derive cwd from process.cwd() in custom runners
- Assert path.isAbsolute(cwd) before calling resolveConfigPath
When it happens
Trigger: Calling resolveConfigPath('./config', './project') or passing a relative cwd from a custom Jest wrapper/runner.
Common situations: Writing a custom test runner on top of jest-config and passing a relative subdirectory string instead of process.cwd(); mocking cwd incorrectly in tests.
Related errors
- Can't find a root directory while resolving a config file pa
- The --config option requires a JSON string literal, or a fil
- Cannot merge config in form of callback
- Whoops! Two projects resolved to the same config path: ${Str
- Jest: Cannot use configuration as an object without a file p
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/6ca9695c74b71263.json.
Report an issue: GitHub.