LoginSignup
1
1

More than 3 years have passed since last update.

herokuへのpushができない!まずは、local環境で動作するか確かめてみよう。

Posted at

はじめに

意気揚々とRailsでwebアプリを作り始めたところ
Precompiling assets failed.が出力されて
git push heroku masterができない...
初っ端から躓きました \(^O^)/

同じようなエラーで悩まされてる方の助けになればと思い、記事を投稿しました。

結論

localでrails serverを実行して出力されたエラーに従うことで、解決しました。

解決までの道のり

git push heroku masterを実行したときのエラーは次の通り

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 herokuアプリ名.
remote:
To https://git.heroku.com/herokuアプリ名.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/herokuアプリ名.git'

ネットでヒットした解決策を片っ端から試すも、あえなく撃沈
ふと、rails serverを試したところ、そもそもlocalでアプリが立ち上がらないことが判明!
設定ファイルいじってるうちにサーバーが起動しなくなってたのね…
エラー内容は次の通り

$ rails s
C:/Users/ユーザ名/environment/アプリ名/config/environment.rb:8:in `<top (required)>': undefined local variable or method `config' for main:Object (NameError)

エラー文にあったファイルを見ると…

environment.rb
# Load the Rails application.
require_relative 'application'

# Initialize the Rails application.
Rails.application.initialize!

# compile ON
config.assets.compile = true #この行が悪さをしていた

ということで次のようにコメントアウトする。

environment.rb
# Load the Rails application.
require_relative 'application'

# Initialize the Rails application.
Rails.application.initialize!

# compile ON
# config.assets.compile = true #この行が悪さをしていた

すると無事railsサーバーが起動してくれました!

背景

本番環境のデータベースとしてPostgreSQLを使う場合は
config.assets.compile = true
の追記が必要とどこかの記事で読んだので追加していたのですが、追加するファイルを間違えてました(゚∀。)アヒャ

そして…

localでうまくいったので、変更をgitにpushした後、herokuへもpushできることを祈りつつ、
git push heroku masterをしたところ
無事、私のhello world!を全世界に公開することができました。

今回の教訓

remoteでうまくいかない場合は、まずlocalから

灯台下暗しでした!

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