{"id":"2ce8bf04661b3732","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.map(ext => `\"${getConfigFilename(ext)}\"`).join(' or ')}.","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: (.+?)\"`\\)\\.join\\(' or '\\)\\}\\.","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/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-config/src/resolveConfigPath.ts#L100-L136","documentation":"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.","triggerScenarios":"Running jest in a directory with no config and no ancestor config; passing a project path that is outside any configured Jest project.","commonSituations":"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.","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"],"exampleFix":"// before: no config present\nnpx jest\n// after: create jest.config.js\nexport default {testEnvironment: 'node'};","handlingStrategy":"validation","validationCode":"import * as fs from 'node:fs';\nimport * as path from 'node:path';\nfunction findConfigUp(dir: string): string | undefined {\n  const exts = ['.js','.ts','.mjs','.mts','.cjs','.cts','.json'];\n  let cur = dir;\n  while (true) {\n    const hit = exts.map(e => path.join(cur, 'jest.config'+e)).find(fs.existsSync);\n    if (hit) return hit;\n    const parent = path.dirname(cur);\n    if (parent === cur) return undefined;\n    cur = parent;\n  }\n}\nif (!findConfigUp(process.cwd())) throw new Error('No jest config found');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add a config as part of project scaffolding","Pin --config in CI scripts","Run jest from the project root"],"tags":["config","cli","setup"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}