{"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/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-config/src/resolveConfigPath.ts#L13-L49","documentation":"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.","triggerScenarios":"Calling resolveConfigPath('./config', './project') or passing a relative cwd from a custom Jest wrapper/runner.","commonSituations":"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.","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"],"exampleFix":"// before\nresolveConfigPath(configFile, './packages/app')\n// after\nresolveConfigPath(configFile, path.resolve('packages/app'))","handlingStrategy":"validation","validationCode":"import * as path from 'node:path';\nif (!path.isAbsolute(cwd)) {\n  cwd = path.resolve(cwd);\n}","typeGuard":"import * as path from 'node:path';\nfunction isAbsolutePath(p: string): boolean {\n  return path.isAbsolute(p);\n}","tryCatchPattern":null,"preventionTips":["Always derive cwd from process.cwd() in custom runners","Assert path.isAbsolute(cwd) before calling resolveConfigPath"],"tags":["config","path","internal"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}