Node.js環境で発生する”npm WARN EBADENGINE Unsupported engine”を解決したい

2021.12.12

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは、CX事業本部 IoT事業部の若槻です。

今回は、Node.js環境でnpm WARN EBADENGINE Unsupported engineが発生するようになったので解決してみました。

前提

まず前提として、Nodeバージョンは14.5.0で、Nodenvを使用しています。

$ node --version
v14.5.0

Nodenvは、1つの環境で複数のNodeバージョンを切り替えて使用可能とするツールです。プロジェクトごとにNodeバージョンを変更したい場合などに便利です。

事象

さてこの環境でnpm installでモジュールインストールを実行すると、npm WARN EBADENGINE Unsupported engineという警告が発生するようになりました。

$  npm install
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@eslint/eslintrc@1.0.5',
npm WARN EBADENGINE   required: { node: '^12.22.0 || ^14.17.0 || >=16.0.0' },
npm WARN EBADENGINE   current: { node: 'v14.5.0', npm: '7.21.1' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@typescript-eslint/eslint-plugin@5.6.0',
npm WARN EBADENGINE   required: { node: '^12.22.0 || ^14.17.0 || >=16.0.0' },
npm WARN EBADENGINE   current: { node: 'v14.5.0', npm: '7.21.1' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@typescript-eslint/experimental-utils@5.6.0',
npm WARN EBADENGINE   required: { node: '^12.22.0 || ^14.17.0 || >=16.0.0' },
npm WARN EBADENGINE   current: { node: 'v14.5.0', npm: '7.21.1' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@typescript-eslint/parser@5.6.0',
npm WARN EBADENGINE   required: { node: '^12.22.0 || ^14.17.0 || >=16.0.0' },
npm WARN EBADENGINE   current: { node: 'v14.5.0', npm: '7.21.1' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@typescript-eslint/scope-manager@5.6.0',
npm WARN EBADENGINE   required: { node: '^12.22.0 || ^14.17.0 || >=16.0.0' },
npm WARN EBADENGINE   current: { node: 'v14.5.0', npm: '7.21.1' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@typescript-eslint/types@5.6.0',
npm WARN EBADENGINE   required: { node: '^12.22.0 || ^14.17.0 || >=16.0.0' },
npm WARN EBADENGINE   current: { node: 'v14.5.0', npm: '7.21.1' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@typescript-eslint/typescript-estree@5.6.0',
npm WARN EBADENGINE   required: { node: '^12.22.0 || ^14.17.0 || >=16.0.0' },
npm WARN EBADENGINE   current: { node: 'v14.5.0', npm: '7.21.1' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@typescript-eslint/visitor-keys@5.6.0',
npm WARN EBADENGINE   required: { node: '^12.22.0 || ^14.17.0 || >=16.0.0' },
npm WARN EBADENGINE   current: { node: 'v14.5.0', npm: '7.21.1' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'eslint@8.4.1',
npm WARN EBADENGINE   required: { node: '^12.22.0 || ^14.17.0 || >=16.0.0' },
npm WARN EBADENGINE   current: { node: 'v14.5.0', npm: '7.21.1' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'eslint-visitor-keys@3.1.0',
npm WARN EBADENGINE   required: { node: '^12.22.0 || ^14.17.0 || >=16.0.0' },
npm WARN EBADENGINE   current: { node: 'v14.5.0', npm: '7.21.1' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'eslint-scope@7.1.0',
npm WARN EBADENGINE   required: { node: '^12.22.0 || ^14.17.0 || >=16.0.0' },
npm WARN EBADENGINE   current: { node: 'v14.5.0', npm: '7.21.1' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'espree@9.2.0',
npm WARN EBADENGINE   required: { node: '^12.22.0 || ^14.17.0 || >=16.0.0' },
npm WARN EBADENGINE   current: { node: 'v14.5.0', npm: '7.21.1' }
npm WARN EBADENGINE }

removed 7 packages, and audited 911 packages in 2s

47 packages are looking for funding
  run `npm fund` for details

1 moderate severity vulnerability

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

どうやらEslint周りのモジュールが要求するNodeバージョンを現在の環境が満たしていないようです。

対処、解決

警告で要求されているNodeバージョンは^12.22.0 || ^14.17.0 || >=16.0.0です。今回は14.17.0へのアップデートを行ってみます。

まずnodenv install 14.17.0を実行すると、node-buildに14.17.0が見つからないためエラーとなりました。

$ nodenv install 14.17.0 
node-build: definition not found: 14.17.0

See all available versions with `nodenv install --list'.

If the version you need is missing, try upgrading node-build:

  git -C /Users/wakatsuki.ryuta/.nodenv/plugins/node-build pull

node-buildは、Nodenvが利用可能なNodeバージョンを管理するために使用するユーティリティです。この中で14.17.0というバージョンがなくインストール可能であるか判断ができないためエラーとなったようです。

先程のエラーで示された次のコマンドを実行してnode-buildを更新します。

$ git -C /Users/wakatsuki.ryuta/.nodenv/plugins/node-build pull

このgit -CはGitコマンドを指定したパスで実行されたかのようにみなせるオプションです。

-C Run as if git was started in instead of the current working directory. When multiple -C options are given, each subsequent non-absolute -C is interpreted relative to the preceding -C . If is present but empty, e.g. -C "", then the current working directory is left unchanged.

更新後、再度nodenv install 14.17.0を実行すると、次はインストールできました。

$  nodenv install 14.17.0
Downloading node-v14.17.0-darwin-x64.tar.gz...
-> https://nodejs.org/dist/v14.17.0/node-v14.17.0-darwin-x64.tar.gz

WARNING: node-v14.17.0-darwin-x64 is in LTS Maintenance mode and nearing its end of life.
It only receives *critical* security updates, *critical* bug fixes and documentation updates.

Installing node-v14.17.0-darwin-x64...
Installed node-v14.17.0-darwin-x64 to /Users/wakatsuki.ryuta/.nodenv/versions/14.17.0

この時点ではまだNodeバージョンは14.5.0です。

$  node --version
v14.5.0

nodenv local 14.17.0を実行してバージョンを切り替えます。

$ nodenv local 14.17.0
$ node --version      
v14.17.0

再度npm installでモジュールインストールを実行すると、今度はnpm WARN EBADENGINE Unsupported engineが発生しなくなりました。

$ npm install

これで解決です!定期的に使用しているNodeバージョンは見直ししたいですね。

参考

以上