【Rails5】Herokuへのデプロイ

基本的に【初心者向け】railsアプリをherokuを使って確実にデプロイする方法【決定版】を参考にさせてもらった. でもやっぱりね, エラーは出るもんですよ.

赤文字で出たエラーがこれ.

Precompiling assets failed.

だからこればっかり検索してたんだけど, あまりいい情報が出てこなかった. それもそのはず. もっと手前で問題が発生していた.

Precompiling assetsfailしたのは, 単なる結果だったというわけ. もっとログを読めばよかったね. ログ全体を見て気になった点は以下の文言.

  • Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.

  • Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.4).

  • Uglifier::Error: Unexpected token name «of», expected punc «;». To use ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true).

結論から言うと, 気にすべきなのは最後のエラーだけ. このエラーに関しては対処法が見つかった. config/environments/production.rbを以下のように編集.

# config/environments/production.rb
-  config.assets.js_compressor = :uglifier
+  config.assets.js_compressor = Uglifier.new(harmony: true)

これでなんとかデプロイできたああ.