{"record":{"id":"6ca9695c74b71263","repo":"jestjs/jest","slug":"cwd-must-be-an-absolute-path-cwd-cwd","errorCode":null,"errorMessage":"\"cwd\" must be an absolute path. cwd: ${cwd}","messagePattern":"\"cwd\" must be an absolute path\\. cwd: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-config/src/resolveConfigPath.ts","lineNumber":31,"sourceCode":"import {\n  JEST_CONFIG_BASE_NAME,\n  JEST_CONFIG_EXT_ORDER,\n  PACKAGE_JSON,\n} from './constants';\nimport {BULLET, DOCUMENTATION_NOTE} from './utils';\n\nconst isFile = (filePath: string) =>\n  fs.existsSync(filePath) && !fs.lstatSync(filePath).isDirectory();\n\nconst getConfigFilename = (ext: string) => JEST_CONFIG_BASE_NAME + ext;\n\nexport default function resolveConfigPath(\n  pathToResolve: string,\n  cwd: string,\n  skipMultipleConfigError = false,\n): string {\n  if (!path.isAbsolute(cwd)) {\n    throw new Error(`\"cwd\" must be an absolute path. cwd: ${cwd}`);\n  }\n  const absolutePath = path.isAbsolute(pathToResolve)\n    ? pathToResolve\n    : path.resolve(cwd, pathToResolve);\n\n  if (isFile(absolutePath)) {\n    return absolutePath;\n  }\n\n  // This is a guard against passing non existing path as a project/config,\n  // that will otherwise result in a very confusing situation.\n  // e.g.\n  // With a directory structure like this:\n  //   my_project/\n  //     package.json\n  //\n  // Passing a `my_project/some_directory_that_doesnt_exist` as a project\n  // name will resolve into a (possibly empty) `my_project/package.json` and","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-config/src/resolveConfigPath.ts#L13-L49","documentation":"Thrown at the top of resolveConfigPath when the cwd argument is not an absolute path. resolveConfigPath later uses path.resolve(cwd, pathToResolve), so a relative cwd would produce incorrect config resolution. The check is path.isAbsolute(cwd).","triggerScenarios":"Calling resolveConfigPath directly with a relative cwd (e.g. '.' or 'src'), or wiring Jest programmatically with process.cwd() replaced by a relative value. Not typically hit via the CLI since Jest sets cwd to an absolute path internally.","commonSituations":"Custom Jest runners or wrappers that pass config.rootDir or a computed relative path as cwd; test harnesses that change process.cwd() before invoking Jest APIs.","solutions":["Pass path.resolve(cwd) (or process.cwd(), which is absolute) as the cwd argument","If calling from user code, ensure cwd starts with '/' (posix) or a drive letter (windows)","Normalize early: const absCwd = path.isAbsolute(cwd) ? cwd : path.resolve(cwd)"],"exampleFix":"// before\nresolveConfigPath('./config', 'src');\n\n// after\nresolveConfigPath('./config', path.resolve('src'));","handlingStrategy":"validation","validationCode":"import * as path from 'node:path';\nfunction resolveCwd(cwd: string): string {\n  if (!path.isAbsolute(cwd)) {\n    throw new Error(`cwd must be absolute, got: ${cwd}`);\n  }\n  return cwd;\n}","typeGuard":"function isAbsolutePath(p: unknown): p is string {\n  return typeof p === 'string' && path.isAbsolute(p);\n}","tryCatchPattern":null,"preventionTips":["Always pass path.resolve(...) or process.cwd() as cwd","Never pass user input or relative config values directly as cwd","Unit-test wrapper code with both relative and absolute inputs"],"tags":["config","paths","argument-validation","programmatic-api"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}