heroku push error: "Could not detect rake tasks"

I'm trying to deploy a basic app and it's not working. Using

git push heroku master 

I got this 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:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/Rakefile:4:in `<top (required)>'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/rake_module.rb:28:in `load'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/rake_module.rb:28:in `load_rakefile'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:689:in `raw_load_rakefile'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:94:in `block in load_rakefile'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:176:in `standard_exception_handling'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:93:in `load_rakefile'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:77:in `block in run'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:176:in `standard_exception_handling'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:75:in `run'
remote:  !     /tmp/build_a1cfcabff50107f84830d908386197b2/vendor/bundle/ruby/2.2.0/gems/rake-11.1.2/bin/rake:33:in `<top (required)>'
remote:  !     vendor/bundle/bin/rake:16:in `load'
remote:  !     vendor/bundle/bin/rake:16:in `<main>'
remote:  !
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)

bundle exec rake -P seems to be working fine.

There's nothing special in my Gemfile, I just added Bootstrap:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5.1'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'bootstrap-sass' 
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
#postgreeSQL for Heroku deployment


group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'
  gem 'sqlite3'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'


  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end
group :production do
  gem 'pg'
  gem 'rails_12factor'
end
ruby "2.2.3"

Well, I don't see why it's happening, since I have another project that is working normally. I checked everything and it still gives me that message.


I had the same issue and it Turns out that I had installed the latest bundler version (bundler-2.2.1) You can check your bundler version by:

  • bundle version

Heroku seems to work well with bundler version 2.1.4. (not sure why) In my case I had to downgrade to version 2.1.4 and make it the default.

In my Ubuntu 20.10 When I type:

  • gem uninstall bundler

It uninstalls bundler version 2.2.1 and I am left with bundler version 2.1.4 which is then declared as the default gem and can't be uninstalled and that's exactly what I wanted. So after that I went to my rails app,

  • Deleted Gemfile.lock
  • bundle install
  • git add .
  • git commit -m "Modified Gemfile.lock"
  • git push origin master
  • git push heroku master

And everything worked perfectly.


Sometimes Heroku throws an issue on deployment about assets. You can precompile assets and push it to Heroku.

RAILS_ENV=production bundle exec rake assets:precompile

Update:

In case of it doesn't work, make sure to add RAILS_SERVE_STATIC_FILES env. to yr server.

Make it enabled or true nor anything :)

Because in Rails <5.1 production.rb has

config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

Heroku: App -> Settings -> "Reveal Config Vars"

Sample: enter image description here


Update January 2020: Heroku has just removed the bundler version as of December to prevent these issues from occurring. They mention it in this article.

Original Post:

I took all these steps when trying to solve the same error:

remote: -----> Installing node-v10.15.3-linux-x64
remote: -----> Detecting rake tasks
remote: 
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:  !     Activating bundler (2.0.1) failed:
remote:  !     Could not find 'bundler' (2.0.1) required by your /tmp/build_2e6c96ff8cd3ab115ee56c51d05c7a28/Gemfile.lock.
remote:  !     To update to the latest version installed on your system, run `bundle update --bundler`.
remote:  !     To install the missing version, run `gem install bundler:2.0.1`
remote:  !     Checked in 'GEM_PATH=/tmp/build_2e6c96ff8cd3ab115ee56c51d05c7a28/vendor/bundle/ruby/2.6.0', execute `gem env` for more information
remote:  !     
remote:  !     To install the version of bundler this project requires, run `gem install bundler -v '2.0.1'`
remote:  !
remote: /app/tmp/buildpacks/b7af5642714be4eddaa5f35e2b4c36176b839b4abcd9bfe57ee71c358d71152b4fd2cf925c5b6e6816adee359c4f0f966b663a7f8649b0729509d510091abc07/lib/language_pack/helpers/rake_runner.rb:106:in `load_rake_tasks!': Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)

Which was happening when trying to deploy in the same way. I followed all the commands in the production environment that the error message provides and that still didn't solve it. My versions:

~/movie_list [master] $ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
~/movie_list [master] $ bundler version
Bundler version 2.0.1 (2019-01-04 commit d7ad2192f)

The solution that worked for me finally came from this issue comment I found on bundler. In order to deploy, I had to remove

BUNDLED WITH
   1.17.1

from my gemfile.lock, and then use git push heroku master.