Heroku RoR deploy issues
The first time i deployed an app on Heroku i went through quite a bit of problems to get it up and running. I quickly researched the errors that I received, and it turns out that my problems with heroku were quite common. Unfortunetly there wasn’t much updated information on these errors, and the answers i found could not solve my issues. So hopefully this post can help you get through these errors much faster than i have.
Before starting an app that you would like to deploy, it is easiest to use the rails new example-api — api -d=postgresql
postgresql flag. Doing so would avoid the pain of needing to switch out of sqlit3 for postgres. After that, it almost felt seamless until it was time to git push heroku master
. After a few seconds of deploying i received my first error message.
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: ! rake aborted!
remote: ! LoadError: cannot load such file -- /tmp/build_a1cfcabff50107f84830d908386197b2/config/application
remote: ! /tmp/build_a1cfcabff50107f84830d908386197b2/Rakefile:4:in `require'
remote: ! .../app/tmp/buildpacks/ruby/lib/language_pack/helpers/rake_runner.rb:102:in `load_rake_tasks!': Could not detect rake tasks
(LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)
For some reason i couldn’t get this to work. After a few failed solutions i found one that finally worked for me.
gem uninstall bundler
For some this simple command can solve that error. Selecting the newer version of bundler (selecting/deleting latest version) and leaving 2.0.2 version should do the trick. Run bundle install
followed by git push heroku master
.
If that doesn’t work try this
- update Ruby version to 2.6.1
gem uninstall bundler
and install againgem install bundler -v 2.0.2
- delete Gemfile.lock and
bundle install
git push heroku master
After pushing, the rake task error was gone, but i had a new error to deal with. The Ruby version you are trying to install does not exist on this stack.
The Ruby version you are trying to install does not exist on this stack.
remote: !
remote: ! You are trying to install ruby-2.6.1 on heroku-20.
remote: !
remote: ! Ruby ruby-2.6.1 is present on the following stacks:
remote: !
remote: ! - cedar-14
remote: ! - heroku-16
remote: ! - heroku-18remote: ! Heroku recommends you use the latest supported Ruby version listed here:
remote: ! https://devcenter.heroku.com/articles/ruby-support#supported-runtimes
remote: !
remote: ! For more information on syntax for declaring a Ruby version see:
remote: ! https://devcenter.heroku.com/articles/ruby-versions
Many people believe the solution would be to change the ruby version number but if you would like to save yourself the hassle i came across a helpful command to change from stack 20 to 18. The error is simply telling us that our version of ruby is not supported by the current stack.
heroku stack:set heroku-18
this command will switch your stack over to heroku-18 which does support rails 2.6.1
Hope this saved you time and solved your errors HAPPY CODING! :)