LoginSignup
1
2

More than 1 year has passed since last update.

【Rails】本番環境でのコンパイル時、Node.jsで困った話

Last updated at Posted at 2021-05-06

環境

Ruby 3.0.1
Rails 6.1.3
Amazon Linux 2 AMI

エラー

AWSにアプリをデプロイしようとしていた時、

 bundle exec rake assets:precompile RAILS_ENV=production

でプリコンパイルを行った際、何やら長文のエラーが起きました。
よく読んでみると何やら原因らしきものを発見

error /var/www/rails/myapp/node_modules/node-sass: Command failed.

原因

どうやら最新のバージョンのNode.jsではnode-sassは非推奨のようです。

とりあえずでNode.jsをインストールしたため、最新バージョンがインストールされていました。

$ nvm install node
Downloading and installing node v16.1.0...
$ node -v
v16.1.0

解決方法

Node.jsのバージョンを下げることで解決しました。

バージョンは、公式サイトでも推奨版とされている14.16.1

手順

$ nvm ls-remote

で変更可能なバージョンを確認

$ nvm install 14.16.1
Downloading and installing node v14.16.1...
Downloading https://nodejs.org/dist/v14.16.1/node-v14.16.1-linux-x64.tar.xz...
############################################################################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v14.16.1 (npm v6.14.12)
$ nvm use 14.16.1
Now using node v14.16.1 (npm v6.14.12)

で変更完了!

$ bundle exec rake assets:precompile RAILS_ENV=production
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/
Exiting!

無事、プリコンパイルが完了しました!

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2