HerokuへPushする際に「Failed to install gems via Bundler.」が出た時の対処法Part2

またしてもこんなにハマるとは思いませんでした。今回はHerokuへPushする際に「Failed to install gems via Bundler.」が出た時の対処法Part2として解決策をまとめます。

※先に以下の記事の内容を確認ください。それでも解決しない場合は今回の記事の内容を試してみてください。

HerokuへPushする際に「Failed to install gems via Bundler.」が出た時の対処法

結論

bundle lock –add-platform x86_64-linuxのコマンドを実行した。

言い方をかえると、アップデートしたbundlerが自分のPCのOSバージョンに未対応だった。なので「私のPCのOSもアップデートしたbundlerに対応させてね」するために、上述のコマンドを実行した。

※Ruby 3.0.0、Rails 6.1.3。2021/03/20時点で最新版のRubyとRailsを使用。

解決手順

エラー遭遇

新しいアプリをHerokuにアップしようと思い、git push heroku masterを実行。すると以下のエラーが発生。

コード

Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 8 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 1.99 KiB | 1.99 MiB/s, done.
Total 5 (delta 2), 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.11
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-3.0.0
remote: -----> Installing dependencies using bundler 2.2.11
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-20"] 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-20"] 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:  !
remote:  ! ## Warning - The same version of this code has already been built: 628ef348416c40b736a444efa2a48fc073369937
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version 628ef348416c40b736a444efa2a48fc073369937
remote:  ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote:  !
remote:  ! If you are developing on a branch and deploying via git you must run:
remote:  !
remote:  !     git push heroku :main
remote:  !
remote:  ! This article goes into details on the behavior:
remote:  !   https://devcenter.heroku.com/articles/duplicate-build-version
remote: 
remote: Verifying deploy...
remote: 
remote: ! Push rejected to pure-mountain-31710.
remote: 
To https://git.heroku.com/pure-mountain-31710.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/pure-mountain-31710.git'

調べた方法がうまくいかない

まずは以下の記事にしたがってローカルとHerokuのbundlerのバージョンを合わせてみる。

HerokuへPushする際に「Failed to install gems via Bundler.」が出た時の対処法

その後Herokuにpushするも先ほどと同様のエラーが発生。

git push heroku (ブランチ名):mainで解決するかもといった記述がエラー文にあるので試してみる。しかしうまくいかない。

結局、上述の記事の通りにやればBundlerの問題は解決していたことが、後からわかった。問題は別で発生していた。

解決手順

何が問題なんだろうなーと思って、よくよくエラーをながめてみた。すると赤文字でもWarningでもないところで、以下のアドバイスが表示されていた。

コード

・・・省略・・・
remote:        Your bundle only supports platforms ["x86_64-darwin-20"] 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.
・・・省略・・・

何をいっているかを簡単にまとめると以下の通りだった。

「あなたのbundlerでは、あなたのPCのOSをサポートしてません。あなたのPCもサポートする設定をして、再度やり直してください。」

これかもと思って、以下の手順を実行。

  1. % bundle lock –add-platform x86_64-linuxのコマンドを実行
  2. Gemfile.lockの記述が追加されるので、その変更をリモートにpush
  3. Herokuへのプッシュを再度トライ

以下実際のコマンドです。

コード

% bundle lock --add-platform x86_64-linux #言われた通りに実行
Fetching gem metadata from https://rubygems.org/............
Resolving dependencies...
Writing lockfile to /Users/shinji/environment/holdem-qa/Gemfile.lock
% git status #git statusの確認
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git restore ..." to discard changes in working directory)
modified:   Gemfile.lock #Gemfile.lockのplatformの部分に自分のPCのOSバージョンが追加で記載されている!
no changes added to commit (use "git add" and/or "git commit -a")
 % git add -A
 % git commit -m "x86_64-linuxの記述をGemfile.lockに追加・更新" #git add & commitを忘れずに
[master fac3465] x86_64-linuxの記述をGemfile.lockに追加・更新
 1 file changed, 3 insertions(+)
% git push heroku master
Enumerating objects: 13, done.
Counting objects: 100% (13/13), done.
Delta compression using up to 8 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 2.32 KiB | 2.32 MiB/s, done.
Total 8 (delta 4), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
・・・省略・・・ 
remote: -----> Compressing...
remote:        Done: 78.7M
remote: -----> Launching...
remote:        Released v6
remote:        https://pure-mountain-31710.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/pure-mountain-31710.git
 * [new branch]      master -> master
% heroku open #無事にデプロイ完了!

まる2日かかりました。苦しかったですが、解決してよかったです。ではまた!

2 COMMENTS

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA