LoginSignup
0
0

More than 3 years have passed since last update.

【Rails】Rails5のアプリでES6の構文を使用し,Herokuにデプロイする場合

Last updated at Posted at 2021-05-07

はじめに

Rails5アプリをHerokuにてのデプロイ作業を行っていた時にUglifier::Error: Unexpected token:~というエラーが発生した時に解決させた方法を記載して行きます。

スクリーンショット 2021-05-07 12.56.04.png

環境

  • Ruby2.6.6
  • Rails 5.2.4

エラー内容

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.
プリコンパイルとはコンパイルする為にの事前処理(機械側が理解できる内容に処理)
とりあえずファイルの読み込みができませんと言うわれています。^^;

どこで処理が止まっているのかログを辿って行くと、

rake aborted!
remote:        Uglifier::Error: Unexpected token: punc ()). To use ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true).

「ES6を使うにはUglifier.new(:harmony => true)でharmony modeを有効にしてね」とのエラー内容です。

なので、

解決策

config/environments/production.rb
config.assets.js_compressor = :uglifier

↓  以下に変更

config.assets.js_compressor = Uglifier.new(harmony: true)

本番環境の設定ファイルを変更してあげれば無事でデプロイができました!^^

終わりに

解決まで無事辿り着けたのもしっかりログを確認できたことでした!
文字の羅列がダーっと流れると読むのに嫌気が感じると思いますが、
ここです! rake aborted!と記してくれているので、
見つけたら解決までそう時間はかからないと思います!
あと解決できると楽しいですしね^^

herokuデプロイにて困っている方の解決案になれば幸いです!
ありがとうございました!😊

0
0
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
0
0