{"id":"1009026bdf843cf9","repo":"eslint/eslint","slug":"could-not-find-config-file-for-fileordirpath","errorCode":null,"errorMessage":"Could not find config file for ${fileOrDirPath}","messagePattern":"Could not find config file for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/config/config-loader.js","lineNumber":479,"sourceCode":"\t * Returns a configuration array for the given directory based on the CLI options.\n\t * This is a synchronous operation and does not read any files from disk. It's\n\t * intended to be used in locations where we know the config file has already\n\t * been loaded and we just need to get the configuration for a file.\n\t * @param {string} fileOrDirPath The path of the directory to retrieve a config object for.\n\t * @returns {FlatConfigArray} A configuration object for the directory.\n\t * @throws {Error} If `dirPath` is not a non-empty string.\n\t * @throws {Error} If `dirPath` is not an absolute path.\n\t * @throws {Error} If the config file was not already loaded.\n\t */\n\tgetCachedConfigArrayForPath(fileOrDirPath) {\n\t\tassertValidFilePath(fileOrDirPath);\n\n\t\tdebug(`Looking up cached config for ${fileOrDirPath}`);\n\n\t\tconst absoluteDirPath = path.resolve(this.#options.cwd, fileOrDirPath);\n\n\t\tif (!this.#configFilePaths.has(absoluteDirPath)) {\n\t\t\tthrow new Error(`Could not find config file for ${fileOrDirPath}`);\n\t\t}\n\n\t\tconst configFilePathInfo = this.#configFilePaths.get(absoluteDirPath);\n\n\t\tif (typeof configFilePathInfo.then === \"function\") {\n\t\t\tthrow new Error(\n\t\t\t\t`Config file path for ${fileOrDirPath} has not yet been calculated or an error occurred during the calculation`,\n\t\t\t);\n\t\t}\n\n\t\tconst { configFilePath } = configFilePathInfo;\n\n\t\tconst configArray = this.#configArrays.get(configFilePath);\n\n\t\tif (!configArray || typeof configArray.then === \"function\") {\n\t\t\tthrow new Error(\n\t\t\t\t`Config array for ${fileOrDirPath} has not yet been calculated or an error occurred during the calculation`,\n\t\t\t);","sourceCodeStart":461,"sourceCodeEnd":497,"githubUrl":"https://github.com/eslint/eslint/blob/f131c034ad91bbf06bcbb6b5e931447a8e419a46/lib/config/config-loader.js#L461-L497","documentation":"Thrown by getCachedConfigArrayForPath() (config-loader.js:479) when the resolved absolute directory path is not present in the internal #configFilePaths map. The cached lookup is synchronous and assumes the config file for that path was already located/loaded via the async APIs; if it was never calculated (or calculated for a different path), there is nothing to return.","triggerScenarios":"Calling getCachedConfigArrayForPath() / getCachedConfigArrayForFile() for a path whose config was not previously loaded via loadAllConfigFilesForDirectory() or findAllConfigFiles(), or calling it before those async operations resolved.","commonSituations":"Using the cached API as if it were async-capable; passing a path with a different normalization (e.g. trailing slash, symlink) than the one stored; calling before awaiting the initial load.","solutions":["Await loadAllConfigFilesForDirectory()/findAllConfigFiles() for the target directory before the cached lookup.","Ensure the path resolves to the same absolute string ESLint stored (use path.resolve(cwd, p)).","If you need config for arbitrary paths on demand, use the async APIs rather than the cached ones."],"exampleFix":"// before\nconst cfg = loader.getCachedConfigArrayForPath(absDir);\n\n// after\nawait loader.findAllConfigFiles({ cwd });\nconst cfg = loader.getCachedConfigArrayForPath(absDir);","handlingStrategy":"validation","validationCode":"function isLoaded(loader, dir) {\n  // No public getter; track via the async load step instead.\n  return loader._configFilePaths?.has(path.resolve(cwd, dir)) ?? false;\n}","typeGuard":"null","tryCatchPattern":"try {\n  return loader.getCachedConfigArrayForPath(dir);\n} catch (e) {\n  if (/Could not find config file/.test(e.message)) {\n    await loader.findAllConfigFiles({ cwd });\n    return loader.getCachedConfigArrayForPath(dir);\n  }\n  throw e;\n}","preventionTips":["Always await the async load before the cached lookup.","Normalize directory paths the same way ESLint does (path.resolve).","Treat cached APIs as read-only views over a pre-warmed cache."],"tags":["config-loader","cache","api-misuse","lifecycle"],"analyzedSha":"f131c034ad91bbf06bcbb6b5e931447a8e419a46","analyzedAt":"2026-08-03T19:53:24.025Z","schemaVersion":2}