{"record":{"id":"1b78ed269152ed76","repo":"jestjs/jest","slug":"could-not-find-a-config-file-based-on-provided-val","errorCode":null,"errorMessage":"Could not find a config file based on provided values:\npath: \"${initialPath}\"\ncwd: \"${cwd}\"\nConfig paths must be specified by either a direct path to a config\nfile, or a path to a directory. If directory is given, Jest will try to\ntraverse directory tree up, until it finds one of those files in exact order: ${JEST_CONFIG_EXT_ORDER}.","messagePattern":"Could not find a config file based on provided values:\npath: \"(.+?)\"\ncwd: \"(.+?)\"\nConfig paths must be specified by either a direct path to a config\nfile, or a path to a directory\\. If directory is given, Jest will try to\ntraverse directory tree up, until it finds one of those files in exact order: (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-config/src/resolveConfigPath.ts","lineNumber":118,"sourceCode":"        configFiles.push(absolutePath);\n      } else {\n        configFiles.push(packageJson);\n      }\n    }\n  }\n\n  if (!skipMultipleConfigError && configFiles.length > 1) {\n    throw new ValidationError(...makeMultipleConfigsErrorMessage(configFiles));\n  }\n\n  if (configFiles.length > 0 || packageJson) {\n    return configFiles[0] ?? packageJson;\n  }\n\n  // This is the system root.\n  // We tried everything, config is nowhere to be found ¯\\_(ツ)_/¯\n  if (pathToResolve === path.dirname(pathToResolve)) {\n    throw new Error(makeResolutionErrorMessage(initialPath, cwd));\n  }\n\n  // go up a level and try it again\n  return resolveConfigPathByTraversing(\n    path.dirname(pathToResolve),\n    initialPath,\n    cwd,\n    skipMultipleConfigError,\n  );\n};\n\nconst findPackageJson = (pathToResolve: string) => {\n  const packagePath = path.resolve(pathToResolve, PACKAGE_JSON);\n  if (isFile(packagePath)) {\n    return packagePath;\n  }\n\n  return undefined;","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-config/src/resolveConfigPath.ts#L100-L136","documentation":"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.","triggerScenarios":"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 '/'.","commonSituations":"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.","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"],"exampleFix":"// before: no config anywhere\njest\n// -> Could not find a config file...\n\n// after: create jest.config.js\n/** @type {import('jest').Config} */\nmodule.exports = { testEnvironment: 'node' };","handlingStrategy":"validation","validationCode":"import * as fs from 'node:fs';\nimport * as path from 'node:path';\nfunction assertConfigDiscoverable(dir: string): void {\n  let current = path.resolve(dir);\n  while (true) {\n    const hasConfig = ['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs', '.json']\n      .some(ext => fs.existsSync(path.join(current, `jest.config${ext}`)));\n    const pkg = path.join(current, 'package.json');\n    const hasPkgJest = fs.existsSync(pkg) && JSON.parse(fs.readFileSync(pkg, 'utf8')).jest;\n    if (hasConfig || hasPkgJest) return;\n    const parent = path.dirname(current);\n    if (parent === current) {\n      throw new Error(`No Jest config found from ${dir} up to filesystem root`);\n    }\n    current = parent;\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["config","discovery","filesystem","missing-config"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}