LoginSignup
4
1

More than 3 years have passed since last update.

【Rails6】herokuデプロイエラー時の対処

Last updated at Posted at 2021-03-18

開発環境

Rails 6.1.1
Ruby 2.7.2
git 2.30.0
heroku/7.50.0 darwin-x64 node-v12.16.2
mac 0S Big Sur 11.2.3

エラーが発生

Railsで作成したアプリをHerokuの登録を行い、

$ git push heroku HEAD

コマンドを入力した際に以下のようなエラーが発生。

! [remote rejected] HEAD -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/*********.git'

bundleのバージョン変更

ターミナルのログを確認すると

buildpack-detect-order
remote: -----> Ruby app detected
remote: -----> Installing bundler 2.2.11
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.7.2
remote: -----> Installing dependencies using bundler 2.2.11

ここからbundleのバージョンがローカルと異なるのが原因と考えバージョンを確認

$ bundle -v →→→ bundler-2.2.6

bundler 2.2.6をアンインストール

$ bundle uninstall -v '2.2.6'

ここでbundle 2.2.11を再インストール
参考 https://qiita.com/manbolila/items/f412a29782e4352d1168

$ bundle _2.2.11_ install

バージョン確認

$ bundle -v →→→ bundler-2.2.11

確認後、git add, commitし,再push!

$ git push heroku HEAD

エラーは変わりませんでした。。

Gemfile.lockの編集

ここで改めてブラウザ上でherokuのBuild Logを確認すると、、

Installing dependencies using bundler 2.2.11
Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
Your bundle only supports platforms ["x86_64-darwin-19"] but your local platform
is x86_64-linux. Add the current platform to the lockfile with `bundle lock
--add-platform x86_64-linux` and try again.

「あなたのプラットフォームはサポートされてないよ」という意味でしょうか?
記述に従いコマンド入力してみます。

$ bundle lock --add-platform x86_64-linux

コマンド入力後、git add, commitし,再pushするとデプロイできました!

まとめ

  • Macやbundleのバージョンによっては Gemfile.lock/PLARFORMSにHerokuの環境構築に必要なgemが入っていないケースがあるようです。

  • Herokuを使用する際はBuild Log確認も忘れずに

参考
https://devcenter.heroku.com/articles/bundler-version#known-upgrade-issues

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