37

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.

jvrn3
  • 600
  • 1
  • 5
  • 18

22 Answers22

23

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.

phoenixstudio
  • 1,776
  • 1
  • 14
  • 19
Elly Ambet
  • 478
  • 4
  • 13
13

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

7urkm3n
  • 6,054
  • 4
  • 29
  • 46
  • 5
    Care to explain why this works? Until then I cannot vote up your answer and frankly few people will, SO answers should help people understand the issue not just provide a line of code. – jasonleonhard Mar 02 '17 at 00:27
  • 3
    RAILS_ENV=production bundle exec rake assets:precompile this doesnt work for me. nothing works really. what else can I try? – dave Oct 28 '18 at 19:17
  • 1
    @dave what's yr issue ? – 7urkm3n Oct 28 '18 at 19:28
  • ( Could not detect rake tasks ensure you can run `$ bundle exec rake -P` against your app and using the production group of your Gemfile. rake aborted!) ...this is the error im getting when i push the appto heroku – dave Oct 28 '18 at 19:32
  • 2
    I ran this on local "RAILS_ENV=production bundle exec rake assets:precompile" and then pushed the app to heroku but same thing happened. – dave Oct 28 '18 at 19:52
  • @dave prob. u need to open a new page. – 7urkm3n Oct 29 '18 at 14:04
9

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.

boyd
  • 331
  • 3
  • 8
7

I struggled with this issue for hours when deploying a Rails 6 application to Heroku.

I was getting this error when I tried deploying the app:

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_3d8b676c/bin/rake:8:in `require': cannot load such file -- rake (LoadError)
remote:  !     from /tmp/build_3d8b676c/bin/rake:8:in `<main>'

The things I tried that did not work:

  • Deleting my Gemfile.lock, running bundle install, committing to the remote master branch and then pushing to heroku.
  • Running RAILS_ENV=production bundle exec rake assets:precompile, committing to the remote master branch and then pushing to heroku.
  • Removing the Bundler version from the Gemfile.lock file, committing to the remote master branch and then pushing to heroku.

Here's how I fixed:

The issue for me was caused by my Project's Bundler version not being the same as that of Heroku. My Project's Bundler version was Bundler 2.2.7, while Heroku's Bundler version was Bundler 2.1.4.

From the build logs of Heroku, I found out that the version of Bundler that Heroku was using was Bundler 2.1.4:

promisepreston@my-pc:~/Projects/my-project$ git push heroku develop:master
Enumerating objects: 193, done.
Counting objects: 100% (193/193), done.
Delta compression using up to 8 threads
Compressing objects: 100% (154/154), done.
Writing objects: 100% (155/155), 37.90 KiB | 3.45 MiB/s, done.
Total 155 (delta 105), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
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-2.7.2
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

Next, I uninstalled the My project's Bundler version 2.2.7, and I was left with the default version which was version Bundler version 2.1.4.

This time when I tried deploying again it was successful.

That's all.

I hope this helps

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
  • 5
    thanks a lot! that worked great! in case anybody wonders this is how you rollback to an older bundler version: `gem uninstall bunder` then `rm Gemfile.lock` and then `gem install bundler --version '2.1.4'` then bundle again, precompile the assets and push to heroku. – Bergrebell Feb 13 '21 at 14:53
  • 3
    @PeterPiper - small typo: 'gem uninstall bundler' – xivusr Feb 20 '21 at 22:28
  • Thanks this fixed it. Except, I don't understand why it fails when using bundler 2.2.11 when my previous apps deploys ok with that version. Same platform (DigitalOcean), almost the same config, just a few months apart. – a.fahmiin Oct 20 '21 at 03:41
6

"Any failure in asset compilation will now cause the push to fail. For Rails 5 asset pipeline support see the Ruby Support page."

The Rails asset pipeline provides an assets:precompile rake task to allow assets to be compiled and cached up front rather than compiled every time the app boots. There are two ways you can use the asset pipeline on Heroku. Compiling assets locally. Compiling assets during slug compilation.

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated.

Before you can compile your assets on Heroku, you’ll need to be able to compile them locally, run this command to debug your assets:

RAILS_ENV=production bundle exec rake assets:precompile

This should complete with no errors. Do NOT check in the assets into git after running this command if using Rails 3 as per Heroku's documentation.

A public/assets directory will be created. Inside this directory you’ll find a manifest.yml which includes the md5sums of the compiled assets in Rails 3. In Rails 4 the file will be manifest-.json. Adding public/assets to your git repository will make it available to Heroku.

git add public/assets
git commit -m "vendor compiled assets"`

Now when pushing, the output should show that your locally compiled assets were detected:

-----> Preparing Rails asset pipeline
   Detected manifest.yml, assuming assets were compiled locally

More help can be found here

And here

jasonleonhard
  • 12,047
  • 89
  • 66
2

use the rbenv to install ruby 2.6.0

 rbenv install 2.6.0

Then go to your project directory and set the ruby version

 rbenv local 2.6.0

Remove the install bundlers

 gem uninstall bundler

Then install the latest bundler,the following will install the latest bundler

 gem install bundler

Then you are good to go.

zawhtut
  • 8,335
  • 5
  • 52
  • 76
2

Since this post came up repeatedly looking for my answer, hopefully this helps someone:

I was getting a similar error on Heroku when deploying updates to an app that was already up and running. The build process wasn't finding basic commands. This is what my error message looked like:

-----> Installing node-v12.16.2-linux-x64
-----> Detecting rake tasks
 !
 !     Could not detect rake tasks
 !     ensure you can run `$ bundle exec rake -P` against your app
 !     and using the production group of your Gemfile.
 !     /tmp/build_a61ee567/bin/rake: line 1: require_relative: command not found
 !     /tmp/build_a61ee567/bin/rake: line 2: require: command not found
 !     /tmp/build_a61ee567/bin/rake: line 3: Rake.application.run: command not found
 !
/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)
ensure you can run `$ bundle exec rake -P` against your app
and using the production group of your Gemfile.
/tmp/build_a61ee567/bin/rake: line 1: require_relative: command not found
/tmp/build_a61ee567/bin/rake: line 2: require: command not found
/tmp/build_a61ee567/bin/rake: line 3: Rake.application.run: command not found
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/ruby.rb:1068:in `rake'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails4.rb:84:in `block (2 levels) in run_assets_precompile_rake_task'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:190:in `log'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails4.rb:78:in `block in run_assets_precompile_rake_task'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-18/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:50:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:46:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails4.rb:77:in `run_assets_precompile_rake_task'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/ruby.rb:112:in `block (2 levels) in compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/ruby.rb:1089:in `allow_git'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/ruby.rb:105:in `block in compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-18/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:50:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:46:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/ruby.rb:94:in `compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails2.rb:62:in `block in compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-18/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:50:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:46:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails2.rb:60:in `compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails3.rb:42:in `block in compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-18/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:50:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:46:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails3.rb:41:in `compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails4.rb:41:in `block in compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-18/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:50:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:46:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails4.rb:40:in `compile'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/bin/support/ruby_compile:20:in `block (2 levels) in <main>'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/base.rb:190:in `log'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/bin/support/ruby_compile:19:in `block in <main>'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:35:in `block in trace'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:17:in `block in instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/vendor/ruby/heroku-18/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:16:in `instrument'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/instrument.rb:35:in `trace'
    from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/bin/support/ruby_compile:15:in `<main>'
 !     Push rejected, failed to compile Ruby app.
 !     Push failed

Bundles, rakes, and starting the app all worked fine locally.

Turns out it was an issue with an update in the ruby buildpack. I locked the buildpack version to an older version with the command heroku buildpacks:set https://github.com/heroku/heroku-buildpack-ruby#v215 -a appname and redeployed. All good after that.

Heroku stack heroku-16 and ruby version 2.3.8

pmilb
  • 273
  • 1
  • 3
  • 11
1

You may also want to add PG Gem file in production in your gem file

GemFile

group :production do
 gem 'pg'
 gem 'rails_12factor'
end

group :development do
 gem 'sqlite3'
end

OR:

# Use sqlite3 as the database for Active Record
gem 'sqlite3', group: [:development, :test]

gem 'rails_12factor', group: :production
gem 'pg', group: :production

Once you added that there save and run the following:

Terminal

gem install bundler
bundle install
git add .
git commit -m "Some comment here..."
git push heroku master
James Brown
  • 836
  • 7
  • 21
1

In my case the error was bin/rake file.

    # frozen_string_literal: true
    #!/usr/bin/env ruby
    
    require_relative '../config/boot'
    require 'rake'
    
    Rake.application.run

Heroku requires #!/usr/bin/env ruby on top, like this:

    #!/usr/bin/env ruby
    # frozen_string_literal: true

    require_relative '../config/boot'
    require 'rake'
    
    Rake.application.run

Solved! o/

Francisco DC
  • 1,111
  • 1
  • 7
  • 5
1

I've been through this very problem and although I am using Ruby, I am not using Rails, so the solution to run the rake tasks was adding the rake gem to the Gemfile.

# Gemfile

...

gem "rake", "~> 13.0"

Hope this becomes helpful to others in the future!

fagiani
  • 2,293
  • 2
  • 24
  • 31
0

Might help someone in the futue, although I think I was recieving this error due to the specific nature I was deploying my application.

For me,

  1. I didn't set the config ENV variables that where required in production before pushing.
  2. I didn't set the build packs required by certain gems to work (needed by gems such as Watir)

After setting the buildpacks on heroku and setting the ENV variables needed in production I managed to get this working.

So make sure that all ENV variables and buildpacks imported on heroku before deploying your repo to heroku.

NemyaNation
  • 983
  • 1
  • 12
  • 22
0

TL;DR; Have gem "better_errors", gem "binding_of_caller", gem 'pry-byebug' in global scope of your Gemfile

In my case it was because I moved these 3 gems from the global scope to development in my Gemfile:

gem "better_errors"

gem "binding_of_caller"

gem 'pry-byebug'

They should probably be only in the development scope, but there's something that I'm missing. So, moving them back outside of the development scope my deploy and rakes work correctly

luigi7up
  • 5,779
  • 2
  • 48
  • 58
0

I'd been getting both

Could not detect rake tasks

and

LoadError: cannot load such file

Turns out I'd got case wrong on a require statment - works fine on Windows (case insensitive filesystem) but fails on Heroku with those errors (quite mis-leading when looking at the 'Could not detect rake tasks')

Straff
  • 5,499
  • 4
  • 33
  • 31
0

None of the answers here fixed the problem for me unfortunately. I was using the suspenders gem to set up my rails application.

Make sure that:

APPLICATION_HOST=foobar RAILS_ENV=production be rake assets:precompile

works with your setup, this way you ensure that there are no issues with the assets compilation.

The suggested fixes with adapting the bundler version don't work, because heroku by default now uses a fixed bundler version (see here).

What fixed it then finally for me was to adapt my rake file and to set the ruby version to 2.6.6. Update your Gemfile and whatever ruby version manager you are using. Also change the .ruby-version file in case you have one. In my case I had to rbenv install 2.6.6 and then I like to use the same ruby version everywhere: rbenv global 2.6.6.

It was this before:

require "standard/rake"# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative 'config/application'

Rails.application.load_tasks
task(:default).clear
task default: [:spec]

if defined? RSpec
  task(:spec).clear
  RSpec::Core::RakeTask.new(:spec) do |t|
    t.verbose = false
  end
end

task default: "bundle:audit"

And then I changed it to this:

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

Rails.application.load_tasks

if defined? RSpec
  task(:spec).clear
  RSpec::Core::RakeTask.new(:spec) do |t|
    t.verbose = false
  end
end

task default: "bundle:audit"

And then it works. Hope I am able to save some of you those 4 hours it took me to fix it.

Hendrik
  • 4,849
  • 7
  • 46
  • 51
0

I had the exact same problem with this output:

remote:        Removing bundler (1.17.3)
remote:        Bundle completed (29.91s)
remote:        Cleaning up the bundler cache.
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:  !     /tmp/build_49740f40/vendor/ruby-2.7.2/lib/ruby/2.7.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'spring' (= 2.1.1) among 96 total gem(s) (Gem::MissingSpecError)
remote:  !     Checked in 'GEM_PATH=/tmp/build_49740f40/vendor/bundle/ruby/2.7.0', execute `gem env` for more information
remote:  !     from /tmp/build_49740f40/vendor/ruby-2.7.2/lib/ruby/2.7.0/rubygems/dependency.rb:323:in `to_spec'
remote:  !     from /tmp/build_49740f40/vendor/ruby-2.7.2/lib/ruby/2.7.0/rubygems/core_ext/kernel_gem.rb:62:in `gem'
remote:  !     from /tmp/build_49740f40/bin/spring:14:in `<top (required)>'
remote:  !     from /tmp/build_49740f40/bin/rake:7:in `load'
remote:  !     from /tmp/build_49740f40/bin/rake:7: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

The problem in my case was the gem 'spring' located in the group :development and was missing for production inside the Gemfile, so I just move out from development and made it available in all environments. Then I run bundle install and push to git and Heroku and everything went well. I just read this documentation from heroku

0

For me, this was caused by the standard gem in the Rakefile (after trying all the other fixes mentioned in other answers).

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
# require "standard/rake"

PatchVault::Application.load_tasks

# task default: [:test, "standard:fix"]

After commengint out lines 5 and 9, things deployed fine.

Ruby 2.7.2, Bundler 2.2.6

John Athayde
  • 580
  • 2
  • 13
0

On the off chance that this helps someone. The Heroku output told me the changes to the gemfile since the last successful build in the error message. I thought that is extremely unlikely to fix the error but on a whim I decided to try it, expecting it not to work.

#/Gemfile
# I used to have my stripe gem like this 
gem 'stripe', '>= 2.8', '< 6.0'
# The format being like this caused the error
gem 'stripe', '< 6.0', '>= 2.8'

Well, I have seen it all now. Software development ladies and gentlemen.

Ali Ove
  • 71
  • 7
0

I hope that this helps someone if you're using Rails 5 and starting a new Heroku app. Nothing else I've seen has worked, and tech support was baffled by it. Here's what I did:

From the Heroku CLI switch back to stack 18 (they're at 20 now): heroku stack:set heroku-18

Then make sure you specify a Ruby version in your gemfile that works with your app: ruby '2.5.3'

0

Just an update for 2022. Same error on Heroku with Ruby 3.1.2, Rails 6 app.

Solution was to add these two gems (see comment for links with explanations):

# https://github.com/gdelugre/origami/issues/81
gem 'matrix'

# https://stackoverflow.com/questions/70500220/rails-7-ruby-3-1-loaderror-cannot-load-such-file-net-smtp
gem 'net-smtp', require: false
gem 'net-imap', require: false
gem 'net-pop', require: false
Cody
  • 436
  • 5
  • 13
0

For the future reference of others since I've also been struggling with the exact issue, but none of the answers have helped (although @Javier Botero pointed me towards right path), here's what I've done to resolve the issue:

  1. Diagnose all the gems that you've installed through gem install
  2. Uninstall all of those gems and pass them into the gemfile
  3. Run bundle install
  4. Push the changes into heroku

In my case the issue was caused by installing Sinatra gem without adding it to gemfile.

0

My problem was that heroku complained about using sqlite3 as db. So I blindly just erased sqlite3 from gemfile.

That threw the error for rake tasks, since rake couldn't find a DB it wasn't working at all.

Fixed by following heroku's guide on swapping sqlite3 to postgresql.

0

I had some weird stuff in my Rakefile, from upgrading this from an older version of Rails. I changed from:


require File.expand_path('../config/application', __FILE__)
require 'rake'

to:

require_relative "config/application"
Duke
  • 7,070
  • 3
  • 38
  • 28