eslint/eslint · error

Could not find config file for ${fileOrDirPath}

Error message

Could not find config file for ${fileOrDirPath}

What it means

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.

Source

Thrown at lib/config/config-loader.js:479

	 * Returns a configuration array for the given directory based on the CLI options.
	 * This is a synchronous operation and does not read any files from disk. It's
	 * intended to be used in locations where we know the config file has already
	 * been loaded and we just need to get the configuration for a file.
	 * @param {string} fileOrDirPath The path of the directory to retrieve a config object for.
	 * @returns {FlatConfigArray} A configuration object for the directory.
	 * @throws {Error} If `dirPath` is not a non-empty string.
	 * @throws {Error} If `dirPath` is not an absolute path.
	 * @throws {Error} If the config file was not already loaded.
	 */
	getCachedConfigArrayForPath(fileOrDirPath) {
		assertValidFilePath(fileOrDirPath);

		debug(`Looking up cached config for ${fileOrDirPath}`);

		const absoluteDirPath = path.resolve(this.#options.cwd, fileOrDirPath);

		if (!this.#configFilePaths.has(absoluteDirPath)) {
			throw new Error(`Could not find config file for ${fileOrDirPath}`);
		}

		const configFilePathInfo = this.#configFilePaths.get(absoluteDirPath);

		if (typeof configFilePathInfo.then === "function") {
			throw new Error(
				`Config file path for ${fileOrDirPath} has not yet been calculated or an error occurred during the calculation`,
			);
		}

		const { configFilePath } = configFilePathInfo;

		const configArray = this.#configArrays.get(configFilePath);

		if (!configArray || typeof configArray.then === "function") {
			throw new Error(
				`Config array for ${fileOrDirPath} has not yet been calculated or an error occurred during the calculation`,
			);

View on GitHub (pinned to f131c034ad)

Solutions

  1. Await loadAllConfigFilesForDirectory()/findAllConfigFiles() for the target directory before the cached lookup.
  2. Ensure the path resolves to the same absolute string ESLint stored (use path.resolve(cwd, p)).
  3. If you need config for arbitrary paths on demand, use the async APIs rather than the cached ones.

Example fix

// before
const cfg = loader.getCachedConfigArrayForPath(absDir);

// after
await loader.findAllConfigFiles({ cwd });
const cfg = loader.getCachedConfigArrayForPath(absDir);
Defensive patterns

Strategy: validation

Validate before calling

function isLoaded(loader, dir) {
  // No public getter; track via the async load step instead.
  return loader._configFilePaths?.has(path.resolve(cwd, dir)) ?? false;
}

Type guard

null

Try / catch

try {
  return loader.getCachedConfigArrayForPath(dir);
} catch (e) {
  if (/Could not find config file/.test(e.message)) {
    await loader.findAllConfigFiles({ cwd });
    return loader.getCachedConfigArrayForPath(dir);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling getCachedConfigArrayForPath() / getCachedConfigArrayForFile() for a path whose config was not previously loaded via loadAllConfigFilesForDirectory() or findAllConfigFiles(), or calling it before those async operations resolved.

Common situations: 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.

Related errors


AI-assisted analysis of eslint/eslint@f131c034ad (2026-08-03). Data as JSON: /data/errors/1009026bdf843cf9.json. Report an issue: GitHub.