36
votes

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.

16
Can you add your gem file as well? - Ray
Yes, but the only thing I added was Bootstrap. I made the front-end for a (very) simple project, tried to deploy and got the error message since yesterday... - jvrn3
Can you post it? I think I know what's wrong - Ray
Try updating your gems with bundle update if that doesn't work, make sure that you're using git properly git init -> git add . -> git commit -m "ready for production etc.." -> git push heroku master - Ray
@jvrn3 can u try to run this RAILS_ENV=production bundle exec rake assets:precompile - 7urkm3n

16 Answers

21
votes

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.

13
votes

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

9
votes

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.

6
votes

"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

5
votes

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

2
votes

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.

1
votes

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

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

0
votes

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.

0
votes

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

0
votes

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/

0
votes

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')

0
votes

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.

0
votes

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
votes

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

0
votes

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.