3
1

More than 3 years have passed since last update.

Rails 環境構築が難しい件 エラーが出たらググるしかない

Posted at

ローカル環境構築

こちらを参考にVScodeで環境構築を進めた
https://qiita.com/wtrt0417/items/1680c007a9ab4d8e4965

しかし、
サーバーがなぜか立たず
terateilで質問
https://teratail.com/questions/320785
一旦全てフォルダを作り直し、Railsチュートリアル の環境でrails のバージョンを
rails -v
Rails 6.0.3.4
に下げて再度構築したらなぜかできるようになりました。

本番環境へデプロイ

rails チュートリアルに沿ってherokuでデプロイする

$git push -u origin master
$git push
$git push heroku master

を実行すると以下のエラーが出てくる

Enumerating objects: 122, done.
Counting objects: 100% (122/122), done.
Delta compression using up to 4 threads
Compressing objects: 100% (104/104), done.
Writing objects: 100% (122/122), 152.56 KiB | 5.26 MiB/s, done.
Total 122 (delta 14), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
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.1.4
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.1.4
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:  !
remote:  ! ## Warning - The same version of this code has already been built: 5064bd53a0e31a4834089451bd2ea48cde9e801c
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version 5064bd53a0e31a4834089451bd2ea48cde9e801c
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 <branchname>: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 young-reaches-17481.
remote: 
To https://git.heroku.com/young-reaches-17481.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/young-reaches-17481.git'

記述にFailed to install gems via Bundler.とあるのでそのままググると...
https://qiita.com/_kazuya/items/5376ab84ed870ceb5a3a
どうやらbundle installしないとできないらしい。(もうしてあったのだがおかしいと思いつつ)

同じようにtryしてみたらbundle installは成功したが、肝心のherokuでは同様のerrorのまま。。。

最後の行に

[remote rejected] master -> master (pre-receive hook declined)

という記述が合ったためこのerror内容で検索
https://www.softel.co.jp/blogs/tech/archives/3569
もしかしてgit のバージョンが更新されてないからできないのか?と推測

$git push -u origin master
Branch 'master' set up to track remote branch 'master' from 'origin'.
Everything up-to-date
$git push
Everything up-to-date
$git push heroku master
#同様のerror発生

しかし現状変わらず...

再度上記のエラーでググる
https://qiita.com/chiaki-kjwr/items/118a5b3237c78d720582
参考になったが、どうやら自分はgitについてあまり理解が足りない?と気付き
ドットインストール のgitを受講 (progateは既に受講済みでなんとなく知っていたが、ブランチとかmasterなどは不明なまま使用していた)

しかし、gitは全く関係なく、、寝て起きてしばらく放置して再度ググったりしてみた
するとエラー名での検索で検索上位7番目ぐらいの記事に
https://yumishin.com/heroku-push-error/

同様のerrorを発見。
手順通り試してみるとまさに同じ状況でした

Herokuではbundlerが2.1.4をインストールしていて

自分のローカルのbundlerのversionは、bundler -vにて調べた結果、2.2.8。
ローカルの方が新しい この違いからエラーが出ていた模様

記事内のコマンドに沿って実行したら...

ようやくデプロイできた!!

いや大変でした。
ありがとう、この記事の人...

環境構築でつまずく人がたくさんいるのがなぜかよくわかりました。

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