ESLint Flat Config (eslint.config.js) が読み込まれない
ESLint v9 から flat config が既定。
.eslintrc.* が残っていると衝突する。
eslint.config.js の配置・export 形式・プラグイン側 flat 対応の有無を順に確認する。
公開: 更新:
要約
eslint.config.js が認識されない場合、(1) ESLint バージョンが v9 未満 / (2) 旧 .eslintrc.* が残って優先される / (3) ESM / CommonJS の取り違え / (4) プラグインが flat 未対応 — のいずれかが原因。eslint --print-config <file> を使えば実際に適用されている設定が読み取れる。
よくある原因
- ESLint v8 系: flat config は v9 から既定。
v8 ではESLINT_USE_FLAT_CONFIG=trueを付けない限り従来形式が優先される - legacy 設定の併存:
.eslintrc.json/.eslintrc.cjs/package.jsonのeslintConfigが残っていると、flat 検出よりそちらが優先されることがある - モジュール形式のミスマッチ:
package.jsonの"type": "module"下でmodule.exportsを書く、あるいはその逆で読み込みに失敗 - プラグインが flat 未対応: 旧
extends: ["plugin:react/recommended"]形式しか提供していないプラグインは flat config のpluginsobject 記法では使えない
解決策
1. バージョンを上げる
npm install --save-dev eslint@latest
npx eslint --version # 9.x.x 以上公式の設定ファイル一覧(新しいタブで開く) のとおり、v9 以降は eslint.config.js / eslint.config.mjs / eslint.config.cjs を自動で検出する。
2. 旧設定を削除する
rm -f .eslintrc .eslintrc.* .eslintignore
# package.json の "eslintConfig" キーも削除ignore 設定は flat config 内に書く。
// eslint.config.js
export default [
{ ignores: ["dist/**", "node_modules/**"] },
// ...
];詳しい移行は migration-guide(新しいタブで開く) を参照。
3. モジュール形式を合わせる
package.json に "type": "module" がある場合は ESM で書く。
// eslint.config.js (ESM)
import js from "@eslint/js";
export default [
js.configs.recommended,
{ rules: { "no-unused-vars": "warn" } },
];CommonJS プロジェクトでは拡張子を .cjs にする。
// eslint.config.cjs
const js = require("@eslint/js");
module.exports = [js.configs.recommended];4. プラグインの flat 対応を確認
import pluginReact from "eslint-plugin-react";
export default [
{
files: ["**/*.{jsx,tsx}"],
plugins: { react: pluginReact },
rules: { "react/jsx-key": "error" },
},
];pluginReact.configs.flat.recommended が用意されていればそれを展開して使う。
プラグインが flat 未対応なら @eslint/eslintrc の FlatCompat で legacy 設定を取り込む手もあるが、可能ならプラグイン側を更新する。
実際に適用されている設定は npx eslint --print-config path/to/file.js で確認できる。
実行例
実際に上記の手順を Node.js 20 環境で動かすと、旧 .eslintrc.json のみが存在する状態では ESLint v9.39.4 が eslint.config.(js|mjs|cjs) を見つけられず終了コード 2 で中断し、eslint.config.mjs を配置して再実行した際に no-unused-vars が検出されて終了コード 1 となり、flat config が正常にロードされたことが確認できる。
$ npx eslint --version
v9.39.5$ npx eslint .
Oops! Something went wrong! :(
ESLint: 9.39.5
ESLint couldn't find an eslint.config.(js|mjs|cjs) file.
From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:
https://eslint.org/docs/latest/use/configure/migration-guide
If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.
eslint の終了コード: 2$ rm -f .eslintrc.json$ npx eslint .
/tmp/tmp.mqPvkCAf8G/index.js
1:7 error 'unused' is assigned a value but never used no-unused-vars
✖ 1 problem (1 error, 0 warnings)
eslint の終了コード: 1(1 = lint 実行され unused を検出=設定ロードOK)— 2026-08-02 時点の出力
検証環境
- 検証日
- 実行環境
node:20
この記事の「実行例」は、上記の環境で実際にコマンドを実行して得られた出力をそのまま掲載しています。 再現手順はリポジトリの検証スクリプトとして管理し、定期的に再実行して出力を更新しています。