yarn installで"The engine "node" is incompatible with this module"というエラーが発生した件


yarnをinstallしようとしたら、以下のエラーが発生しました

error [email protected]: The engine "node" is incompatible with this module.
Expected version "6.* || 8.* || >= 10.*". Got "9.5.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

環境

Ruby: 2.6.3
Rails: 5.2.3

メッセージを和訳してみた

「バージョンは、6.* または8.* または10.*以上がいいんだけど、あなたは9.5.0だったよ」
てなとこかな?

解決策

nodeのバージョンを確認

$ node -v
v9.5.0

やっぱし。

インストール済みのnodeのバージョンを確認

$ nvm ls
      v8.0.0
      v8.9.0
      v8.11.1
      v8.16.0
->    v9.5.0
      v9.10.0
       system
default  v9.5.0

9.5.0以外にもインストールされてた。

インストールできるバージョン一覧を表示させる

$ nvm ls-remote
        v0.1.14
        v0.1.15
        v0.1.16
// 省略
        v13.3.0
        v13.4.0
        v13.5.0

めちゃめちゃたくさん出てきた。

特定のバージョンをインストールする

今回は10.0.0にします。

$ nvm install 10.0.0
Downloading and installing node v10.0.0...
Downloading https://nodejs.org/dist/v10.0.0/node-v10.0.0-darwin-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Now using node v10.0.0 (npm v5.6.0)

バージョンを確認


$ node -v
v9.5.0

まだ変わってなかった。

バージョンを固定する

$ nvm use 10.0.0
Now using node v10.0.0 (npm v5.6.0)

再度、バージョンを確認する

$ node -v
v10.0.0

バージョンを変更できた。

yarnをインストールする

$ yarn install

無事にインストール成功!