LoginSignup
22
25

More than 3 years have passed since last update.

[Rails] herokuデプロイエラー Precompiling assets failed.

Posted at

備忘録です

Railsでアプリ作成し、herokuにデプロイしようとしたところgit push heroku masterでエラーが出たので、解決方法を残しておきます。

デプロイまでの流れ

【初心者向け】railsアプリをherokuを使って確実にデプロイする方法【決定版】を参考にしました。

エラー解決参考記事

Uglifier::Error: Unexpected character '`' Herokuデプロイ時のエラー解消方法を参考にしました。

本題

herokuへデプロイするぞというところから書きます。
git push heroku masterを実行したところ、「Precompiling assets failed.」エラーが、、、

remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to golfmatch.
remote: 
To https://git.heroku.com/golfmatch.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/アプリ名'

Precompiling assets failed.

プリコンパイルってなんだ?
調べました。

プリコンパイルとは、
コンパイルするための事前処理(読んで字の如し)
コンパイラ(翻訳者)が理解できるソースにする処理だそう。

コンパイルとは、
コンパイルとは、エディタで書いたプログラミング言語(高水準言語)を機械語に変換する作業。
PC:機械語で命令
人間:機械語は書きにくいからプログラミング言語(高水準言語)で記述

ニュアンスが掴めればでいいでしょう。

調べていくうちに、目立つところばかり見るな、ログを見よと言われた。
上に辿ってくと、

rake aborted!
remote:        Uglifier::Error: Unexpected character '`'

非同期通信の際に書いた、バックティック文字がUnexpectedですと。
ローカルではちゃんと動いていたので記述ミスではない。

とりあえずエラー文で検索。ドンピシャヒットしました。
config>environments>production.rbの下記を通り編集しました。

production.rb
config.assets.js_compressor = :uglifier
#これをコメントアウトする

# config.assets.js_compressor = :uglifier

これで再度git push heroku masterを実行したらデプロイできました!

ログを辿る大切さが身に染みて分かりました。
ありがとうございました!!

22
25
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
22
25