開発したアプリなど一覧

Rails アプリをデプロイしたら nodejs が古いと言われたので n で最新版にした

アフィリエイトリンクを含む場合があります

Rails アプリを開発し本番サーバーに capistrano でデプロイしようとしたところ、以下のようなエラーが発生した。

Tasks: TOP => deploy:assets:precompile => deploy:yarn_install (See full trace by running task with --trace) The deploy has failed with an error: Exception while executing as username@example.com: cd /home/username/project/example/releases/20200225085614 && yarn install --silent --no-progress --no-audit --no-optional exit status: 1 warning sha.js@2.4.11: Invalid bin entry for "sha.js" (in "sha.js"). error @rails/webpacker@4.2.2: The engine "node" is incompatible with this module. Expected version ">=8.16.0". Got "8.10.0" error Found incompatible module. cd /home/username/project/example/releases/20200225085614 && yarn install --silent --no-progress --no-audit --no-optional stderr: Nothing written

@rails/webpacker が nodejs の 8.16.0 以上を要求しているが見つかったのは 8.10.0 で動作条件を満たさない、という事らしい。

確かにサーバーの nodejs のバージョンを確認すると 8.10.0 となっている。

$ nodejs -v v8.10.0

どうやら ubuntu の apt ではあまり新しいのが入らないようなので n を利用する。npm で n をインストールしよう。

$ sudo npm install n -g /usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n /usr/local/lib └── n@6.3.1

インストールできたら n で nodejs の最新安定板をインストールする。

$ sudo n stable

installing : node-v12.16.1 mkdir : /usr/local/n/versions/node/12.16.1 fetch : https://nodejs.org/dist/v12.16.1/node-v12.16.1-linux-x64.tar.xz installed : v12.16.1 (with npm 6.13.4)

Note: the node command changed location and the old location may be remembered in your current shell. old : /usr/bin/node new : /usr/local/bin/node To reset the command location hash either start a new shell, or execute PATH="$PATH"

最後に既存の nodejs と npm を削除してログインしなおすかシェルを再読み込みなどする。

$ sudo apt purge -y nodejs npm

$ exec $SHELL -l # もしくは exit して再ログインとか

nodejs のバージョン確認。

$ node -v v12.16.1

これで OK, 再度 Rails をデプロイしたところ正常に完了した。

Sponsored Link

コメント

タイトルとURLをコピーしました