Rails を使ってサンプルアプリを作っていたときの話
ある程度の機能を付けたからherokuにデプロイしようとしたら....
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 <アプリ名>.
remote:
To https://git.heroku.com/<アプリ名>
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/<アプリ名>
今出ているエラーを見てみると
Precompiling assets failed
プリコンパイルができなかったみたいなエラー
error: failed to push some refs to ~~~
合ってるかわかりませんが、いくつかpushできないファイルがあったよというエラー
ここだけ見ても解決しそうにないので、こんな時はターミナルのログを見たら原因が見つかるかもしれません!
ちょっとログを遡ってみると、、、、
remote: Running: rake assets:precompile
remote: rake aborted!
remote: NoMethodError: undefined method `new' for :Uglifier:Symbol
それっぽいのがありました!
何となく書いてあることを理解しようとしてみました。
まず1行目はプリコンパイルを行なっているような感じ
2行目はabortedを直訳してみると、打ち切られたつまり何か不具合があるから中止したってことだと思います。
3行目はそのままでメソッドが定義されていないかスペルミス等で合致するメソッドがない状態
ひとまずプリコンパイルの動作を記載してあるproduction.rbを見てみました。
config.assets.js_compressor = :Uglifier.new(harmony: true)
調べてみたところ、Uglifierの前に":"は要らないのでこれを消した後に再度 herokuにデプロイしてみます。
config.assets.js_compressor = Uglifier.new(harmony: true)
調べた感じこれで解決しそうですが、、
結果は
remote: Running: rake assets:precompile
remote: rake aborted!
remote: SyntaxError: /tmp/build_debf70f6/config/environments/production.rb:26: syntax error, unexpected tIDENTIFIER, expecting end
remote: ...lifier.new(harmony: true)
remote: ... ^~~~~~
はい、またエラーが出ました笑
でもさっきとエラー文が変わっています。
SyntaxError: ~~
構文エラーで間違った書き方をしている時に出ます。
さきほど構文の誤りを修正したので、どこが間違っているかなとコードをじっくりみた結果
(harmony; true)
の後に^~~~~
と書いてあることに気づきました
何かな?と実際に書いてある(harmony: true)
にカーソルを持っていくと原因がわかりました。
全角スペースが入っていたのです
実際書いている時は、スペースを加えた覚えがないのですがいつの間にか入っていました笑
正直このエラーで2時間くらい原因を調べてたので、アホやなと思いましたがもしまたスペースが入ってしまっていた時にすぐに対処できるでしょうかそのための2時間だったと思って前向きにいきます笑
記録用として書きました。
間違い等ありましたらご指摘ください!