Heroku スターターガイド (Rails 6.x)に従ってRailsアプリをHerokuにデプロイしようとしたらエラーが出た。
理解はしていないが解決はできました。
環境
症状
エラーまでの手順再現;
# railsアプリ作成 rails new myapp --database=postgresql cd myapp # データベース作成 rails db:create # gitコミット git add . git commit -m "init" # herokuアプリ作成 heroku create
この後に git push
コマンドでherokuにデプロイしようとすると、エラーが出てrejectされた;
% git push heroku main 略 remote: ! remote: ! Could not detect rake tasks remote: ! ensure you can run `$ bundle exec rake -P` against your app remote: ! and using the production group of your Gemfile. remote: ! /tmp/build_176a3f7d/config/boot.rb:4:in `require': cannot load such file -- bootsnap/setup (LoadError) remote: ! from /tmp/build_176a3f7d/config/boot.rb:4:in `<top (required)>' remote: ! from /tmp/build_176a3f7d/bin/rake:3:in `require_relative' remote: ! from /tmp/build_176a3f7d/bin/rake:3:in `<main>' remote: ! remote: /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/helpers/rake_runner.rb:106:in `load_rake_tasks!': Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError) remote: ensure you can run `$ bundle exec rake -P` against your app remote: and using the production group of your Gemfile. remote: /tmp/build_176a3f7d/config/boot.rb:4:in `require': cannot load such file -- bootsnap/setup (LoadError) 略 remote: Verifying deploy... remote: remote: ! Push rejected to shrouded-shelf-31491. remote: To https://git.heroku.com/shrouded-shelf-31491.git ! [remote rejected] main -> main (pre-receive hook declined) error: failed to push some refs to 'https://git.heroku.com/shrouded-shelf-31491.git'
解決
Heroku スターターガイド (Rails 6.x)の日本語記事の内容が古かった。
日本語版にはなかったコマンドが英語版には書いてある。
どうやら以下の手順を踏まないといけないらしい;
rails new myapp --database=postgresql cd myapp rails db:create # 次のコマンドを実行する必要がある; bundle lock --add-platform x86_64-linux --add-platform ruby git add . git commit -m "init" heroku create git push heroku main
そうすると、最後の git push
でエラーが出ずにデプロイが成功する;
remote: Verifying deploy... done. To https://git.heroku.com/shrouded-shelf-31491.git * [new branch] main -> main
heroku open
コマンドを実行すると、アプリがブラウザで開く。
結論
日本人は情弱