できない.dev

ESLint「/* eslint-env */ comments are no longer supported」の原因と直し方

/* eslint-env */ comments are no longer supported は、ESLint 10 が eslint-env コメントを見つけると出す。
コメントを消し、グローバル変数を設定ファイルの languageOptions.globals に書けば直る。

公開:

症状できない · exit 1
npx eslint src
…
  1:1   error  /* eslint-env */ comments are no longer supported
  2:14  error  'process' is not defined                           no-undef
  3:1   error  'console' is not defined                           no-undef
解決後できた · exit 0
npx eslint src

2026-11-07 に node:24(ESLint 10.14.0 / Node.js 24.22.2) で実際に打って取った出力。検証環境の詳細

要約

/* eslint-env */ comments are no longer supported は、ESLint 10 が /* eslint-env node */ のようなコメントを見つけると出すエラーだ。
eslint-env は ESLint 8 までの設定形式(eslintrc)の書き方で、9 で既定になった flat config では効かない。
9 は ESLintEnvWarning を出すだけだったが、10.0 からはエラーとして数え、終了コードが 1 になる。

コメントを消し、グローバル変数は設定ファイルの languageOptions.globals に書けば直る。
npx eslint --fix を打っても、コメントは消えなかった。

実行例

node:24 のコンテナで ESLint 10.14.0 を動かすと、eslint-env コメントの行がエラーになり、終了コード 1 で終わった。
/opt/v9 は同じファイルを ESLint 9 で打ったもので、警告を出したうえで no-undef で落ちている。

$ cat src/server.js
/* eslint-env node */
const port = process.env.PORT || 3000;
console.log(`listening on ${port}`);
$ npx eslint src
/tmp/tmp.E9NGjyXICr/src/server.js
  1:1   error  /* eslint-env */ comments are no longer supported
  2:14  error  'process' is not defined                           no-undef
  3:1   error  'console' is not defined                           no-undef
 
/tmp/tmp.E9NGjyXICr/src/server.test.js
  1:1  error  /* eslint-env */ comments are no longer supported
  2:1  error  'describe' is not defined                          no-undef
  3:3  error  'it' is not defined                                no-undef
 
✖ 6 problems (6 errors, 0 warnings)
$ echo $?
1
$ npx eslint --fix src
/tmp/tmp.E9NGjyXICr/src/server.js
  1:1   error  /* eslint-env */ comments are no longer supported
  2:14  error  'process' is not defined                           no-undef
  3:1   error  'console' is not defined                           no-undef
 
/tmp/tmp.E9NGjyXICr/src/server.test.js
  1:1  error  /* eslint-env */ comments are no longer supported
  2:1  error  'describe' is not defined                          no-undef
  3:3  error  'it' is not defined                                no-undef
 
✖ 6 problems (6 errors, 0 warnings)
$ echo $?
1
$ grep -rn eslint-env src
src/server.test.js:1:/* eslint-env jest */
src/server.js:1:/* eslint-env node */
$ npx eslint src
(node:159) ESLintEnvWarning: /* eslint-env */ comments are no longer recognized when linting with flat config and will be reported as errors as of v10.0.0. Replace them with /* global */ comments or define globals in your config file. See https://eslint.org/docs/latest/use/configure/migration-guide#eslint-env-configuration-comments for details. Found in /opt/v9/src/server.js at line 1.
(Use `node --trace-warnings ...` to show where the warning was created)
 
/opt/v9/src/server.js
  2:14  error  'process' is not defined  no-undef
  3:1   error  'console' is not defined  no-undef
 
/opt/v9/src/server.test.js
  2:1  error  'describe' is not defined  no-undef
  3:3  error  'it' is not defined        no-undef
 
✖ 4 problems (4 errors, 0 warnings)
 
(node:159) ESLintEnvWarning: /* eslint-env */ comments are no longer recognized when linting with flat config and will be reported as errors as of v10.0.0. Replace them with /* global */ comments or define globals in your config file. See https://eslint.org/docs/latest/use/configure/migration-guide#eslint-env-configuration-comments for details. Found in /opt/v9/src/server.test.js at line 1.
$ echo $?
1
$ npm install -D globals
added 1 package in 302ms
$ echo $?
0
$ cat eslint.config.mjs
import js from "@eslint/js";
import { defineConfig } from "eslint/config";
import globals from "globals";
 
export default defineConfig([
  js.configs.recommended,
  { languageOptions: { globals: globals.node } },
  {
    files: ["**/*.test.js"],
    languageOptions: { globals: globals.jest },
  },
]);
$ cat src/server.js
const port = process.env.PORT || 3000;
console.log(`listening on ${port}`);
$ npx eslint src
$ echo $?
0

— 2026-11-07 時点の出力

検証環境Node.js 24.22.2 / npm 11.19.1 / Python 3.11.2 / 2026-11-07 検証(ほか 2 件)
検証日
実行環境
node:24 Debian GNU/Linux 12 (bookworm)
バージョン
  • Node.js 24.22.2
  • npm 11.19.1
  • Python 3.11.2
  • Git 2.39.5
  • ESLint 10.14.0

この記事の「実行例」は、上記の環境で実際にコマンドを実行して得られた出力をそのまま掲載しています。 再現手順はリポジトリの検証スクリプトとして管理し、定期的に再実行して出力を更新しています。

解決策

1. コメントを消して globals を設定に書く

まず、eslint-env が残っているファイルを探す。

grep -rn eslint-env src

globals パッケージを入れ、コメントで指定していた環境を languageOptions.globals に移す。
テストのファイルだけ環境が違うときは、files で対象を絞った設定を足す。

npm install -D globals
import js from "@eslint/js";
import { defineConfig } from "eslint/config";
import globals from "globals";
 
export default defineConfig([
  js.configs.recommended,
  { languageOptions: { globals: globals.node } },
  {
    files: ["**/*.test.js"],
    languageOptions: { globals: globals.jest },
  },
]);

設定を書いたら、各ファイルの /* eslint-env ... */ の行を消す。
設定にグローバル変数がそろっていれば、コメントを消すだけで通る。
ブラウザで動くファイルには globals.browser を渡す。

2. 1 ファイルだけなら /* global */ を使う

設定を分けるほどでもないファイルは、/* global describe, it */ のように、使うグローバル変数の名前をコメントで並べる。
9 の ESLintEnvWarning も、/* global */ への置き換えか設定ファイルへの移動を勧めている。
書き方は移行ガイド(新しいタブで開く)にある。

よくある原因

  1. ESLint を 10 に上げた。
    9 の ESLintEnvWarning の文面には、10.0 からエラーとして報告すると書かれている。
    10 ではそのとおり、コメントの行にルール名の無いエラーが出る。
  2. グローバル変数をコメントで足していた。
    flat config はコメントを読まないので、設定ファイルに globals が無いと process や describe が no-undef で報告される。
    この no-undef は 9 でも出ていた。