LoginSignup
0
0

More than 1 year has passed since last update.

RailsアプリをHerokuにプッシュしたときに、「Failed to install gems via Bundler.」とエラーがでた時の解決方法

Posted at

環境

  • Ruby 2.6.6
  • Rails 6.0.3

発生したエラー

Railsで作成したアプリケーションをGitHubにプッシュした後に、Herokuへプッシュしようとしたところ、以下の通りエラーが出て、Herokuへのプッシュができませんでした。

$ git push heroku master
Enumerating objects: 114, done.
Counting objects: 100% (114/114), done.
Delta compression using up to 8 threads
Compressing objects: 100% (96/96), done.
Writing objects: 100% (114/114), 147.51 KiB | 6.15 MiB/s, done.
Total 114 (delta 7), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote:  !     Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
remote:                         Detected buildpacks: Ruby,Node.js
remote:                         See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order
remote: -----> Ruby app detected
remote: -----> Installing bundler 2.2.33
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.7.5
remote: -----> Installing dependencies using bundler 2.2.33
remote:        Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
remote:        Your bundle only supports platforms ["x86_64-darwin-19"] but your local platform
remote:        is x86_64-linux. Add the current platform to the lockfile with `bundle lock
remote:        --add-platform x86_64-linux` and try again.
remote:        Bundler Output: Your bundle only supports platforms ["x86_64-darwin-19"] but your local platform
remote:        is x86_64-linux. Add the current platform to the lockfile with `bundle lock
remote:        --add-platform x86_64-linux` and try again.
remote: 
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !       Push rejected to immense-bastion-06797.
remote: 
To https://git.heroku.com/immense-bastion-06797.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/immense-bastion-06797.git'

解決方法

エラー文の下の方にある「Failed to install gems via Bundler.」という文字が赤く表示されているため、その付近にエラーの原因と解決方法のヒントがありそうです。
よく見ると、「Failed to install gems via Bundler.」というエラー文の上に、「bundle lock --add-platform x86_64-linuxというコマンドを実行して再試行してください。」といった内容の文言が記載されていることが分かります。
実際に、ターミナルでこのコマンドを実行して、再度Herokuへプッシュしてみます。

$ bundle lock --add-platform x86_64-linux

$ git add .

$ git commit -m "Gemfile.lock fix"

$ git push && git push heroku master

無事Herokuへのプッシュができました。

参考

まとめ

  • 今回のエラーは、ローカル環境のbundlerとHeroku環境のbundlerのバージョンに相違があったため発生したものだということが分かりました。
  • 今回はローカル環境のbundlerのバージョンをそのままにしておきたかったのでこの方法で対処しましたが、またこのエラーが発生した時は、ローカル環境のbundlerのバージョンとHeroku環境のbundlerのバージョンを一致させる方法で解決したいと思います。
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