2

I get the error:

remote:  !     Could not detect rake tasks
 
04:36
 
remote:  !     ensure you can run `$ bundle exec rake -P` against your app
 
04:36
 
remote:  !     and using the production group of your Gemfile.
 
04:36
 
remote:  !     /tmp/build_aa020f9e/bin/rake:8:in `require': cannot load such file -- rake (LoadError)
 
04:36
 
remote:  !     from /tmp/build_aa020f9e/bin/rake:8:in `<main>'

when running a Heroku deployment pipeline from Codeship

/bin/rake looks like this

#!/usr/bin/env ruby
begin
  load File.expand_path('../spring', __FILE__)
rescue LoadError => e
  raise unless e.message.include?('spring')
end
require_relative '../config/boot'
require 'rake'
Rake.application.run

so line 8 is require 'rake'

I tried adding gem rake explicitly to my gemfile

Then because production group is mentioned I tried

group :production do
  gem 'rake'
end

None of this works and so my code push is rejected by Heroku

remote:  !     Push rejected, failed to compile Ruby app.
 
04:36
 
remote: 
 
04:36
 
remote:  !     Push failed

Any ideas anyone?I see a similar post on StackOverflow rails cannot load such file -- rake (LoadError) but without a solution?

Craig Miles
  • 447
  • 4
  • 18
  • try to use bundle exec command_to_be_executed, like bundle exec sidekiq. – Mrinal Verma Feb 12 '21 at 11:21
  • `Push rejected, failed to compile Ruby app.` check in [`build.log`](https://i.imgur.com/kF18DAJ.png) why it failed to compile Ruby app. – Tin Nguyen Feb 12 '21 at 11:29
  • Thanks for the responses folks but it is the git push heroku that fails a) I cant see that I can "bundle exec" this command and b) I already posted the error from build.log. The Ruby app doesnt build because of the error: /tmp/build_aa020f9e/bin/rake:8:in `require': cannot load such file -- rake (LoadError) from require 'rake' in bin/rake – Craig Miles Feb 14 '21 at 13:20

2 Answers2

3

[I've edited this original response to include a solution]

I have this exact issue too, with an open ticket with Heroku. No response yet, sadly but I found an answer elsewhere via a lucky hit in Google.

Context, for future reference and search engines

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

As you've doubtless already found, the suggested bundle exec rake -P command above works fine with any Rails.env setting locally. I, too, tried adding rake to Gemfile explicitly but this made no difference, nor did precompiling assets. Other things to note:

  • All gems build successfully
  • This deploy would prompt and update from Heroku-18 to the Heroku-20 platform; does yours?
  • Rails 5 latest patch, but not Rails 6 yet
  • Ruby 2.7.2

I don't use Spring so my bin/rake is simpler:

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

...and as with your more complex code, it's definitely the require 'rake' that fails.

Solution

I can't take credit - it's this answer:

...that solved it, only you need to change from 2.1.2 to 2.1.4. Copy-pasting the above solution - again this is not my work, the credit belongs to the OP above:

gem uninstall bundler
gem install bundler --version '2.1.4' # If this doesn't work - see below

rm Gemfile.lock
bundle install

git add Gemfile.lock
git commit -m "Downgrade Bundler to match current Heroku version, so that deployments succeed"
git push heroku

This has solved the issue in my case. Seems like an utterly bizarre solution, but there you go.

If you don't seem to be unable to downgrade Bundler

In the comments on this answer, the OP notes:

Because Bundler version 2.2.10 was installed for me as the "default" I hadnt realised Gem bundler-2.1.4 cannot be uninstalled via gem uninstall bundler Using the cleanup_bundler script documented here enabled me to downgrade to v2.1.4 properly. This then did fix the rake problem.

$ gem uninstall bundler
=> Gem bundler-2.2.10 cannot be uninstalled because it is a default gem

StackOverflow prefer answers to be inline rather than linked externally as external links can break, so once again noting that credit goes to the article linked above:

From all the references I can find, the only way to remove it is to delete the bundler-2.1.4.gemspec file from the gem path. The following commands did the trick for me [...] I wrote a script for you:

#!/usr/bin/env ruby

gempaths = `gem env gempath`.split(":")
gempaths.each do |gempath|
  # lookup bundler-*.gemspec files and delete them
  # this is the only way to completely cleanup default bundler
  # Note: the bundler gemspecs' paths are different for CRuby and JRuby
  Dir.glob(gempath.strip + "/specifications/**/bundler-*.gemspec").each { |p| File.delete(p) }
end

# Remember to make this file executable

...so hopefully if you save that as a .rb file somewhere convenient, chmod u+x foo.rb and ./foo.rb - that might solve the problem.

Andrew Hodgkinson
  • 4,379
  • 3
  • 33
  • 43
  • Thanks for the post Andrew. I cant even work out how to place a support ticket with Heroku? When I click the "Create a Ticket" button it just brings me back to the help page. I am using Ruby 2.7.2 and Rails 6.1.2 Further down in the trace I get errors related to run_assets_precompile_rake_task so I am toying with the idea that it is something to do with Webpacker and the node installation relating to assets but I am just beginning to try to explore that with the help of https://devcenter.heroku.com/articles/nodejs-support#customizing-the-build-process I'll let you know how I go. – Craig Miles Feb 16 '21 at 02:00
  • It's been well over a day and they haven't even acknowledged the ticket other than an automated e-mail saying they only look at them during USA business hours. I don't think you're missing much! :-/ – Andrew Hodgkinson Feb 16 '21 at 02:43
  • Hope you hear back from them soon. I really have a feeling that it is this that is failing, but no solution yet: https://devcenter.heroku.com/articles/ruby-support#rails-5-x-applications As a final task in the compilation phase, the assets:precompile Rake task is executed if you have a assets:precompile Rake task defined, and don’t have a public/assets/manifest-*.json file. This will compile all assets and put them in your public directory. If the rake detection or the asset compilation task fails, the deploy will fail as well. For more information refer to Rails Asset Pipeline on Heroku. – Craig Miles Feb 16 '21 at 13:37
  • Yeah except I already tried precompilation (which adds the manifest etc.) and it failed in the same way. The failure we see isn't the usual one that's more widely documented for the Heroku asset compilation hiccup. Out of interest, what Rails version are you on and is this for the Heroku-18 env, Heroku-20, or are you on Heroku-18 with this deployment being the event that would cause the Heroku-20 update? – Andrew Hodgkinson Feb 16 '21 at 21:49
  • Right - solution found in my case - see edited answer above, and please note credit to the original at https://stackoverflow.com/a/65604896/ so give that an upvote if nothing else. Hope it works for you too - fingers crossed. – Andrew Hodgkinson Feb 16 '21 at 22:04
  • Thanks for the ongoing assistance https://stackoverflow.com/users/75028/andrew-hodgkinson. – Craig Miles Feb 17 '21 at 03:17
  • Unfortunately this still didnt work for me. I followed the commands listed in my local environment and installed bundler gem v2.1.4 but when I execute bundler -v => Bundler version 2.2.10 Does that make sense? The node buildpack installs ok and then I get 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 then I get the same rake errors. – Craig Miles Feb 17 '21 at 03:24
  • Ha! Because Bundler version 2.2.10 was installed for me as the "default" I hadnt realised Gem bundler-2.1.4 cannot be uninstalled via gem uninstall bundler Using the cleanup_bundler script documented here https://dev.to/st0012/completely-remove-the-default-bundler-from-ci-environment-j0c enabled me to downgrade to v2.1.4 properly. This then did fix the rake problem. Many thanks for the solution! I dont know if you want to modify it slightly for my observations? – Craig Miles Feb 17 '21 at 04:46
  • Thanks - I've updated the answer accordingly. – Andrew Hodgkinson Feb 17 '21 at 22:21
  • One last followup - an upvote on the answer reminded me that this still exists, so I checked on my Heroku ticket. They closed it, without even so much as a single response or acknowledgement of any kind. Note that I am on a paid Heroku tier, not the free service. – Andrew Hodgkinson May 07 '21 at 01:32
2

I just had this problem and Heroku seems to have added a section to the official documentation that worked for me:

Bundler 2.2.3+

An app’s Gemfile.lock that is generated with Bundler 2.2.3 locally may not work on Heroku unless the Linux platform is explicitly “locked”:

$ bundle lock --add-platform ruby
$ bundle lock --add-platform x86_64-linux
$ bundle install
$ git add . ; git commit -m "Bundler fix"
kizzx2
  • 18,775
  • 14
  • 76
  • 83
  • 2022, Rails 7; `bundle lock --add-platform ruby` got me past the OP's error. Recommend you give this a try before other suggestions above. – Merovex Jun 04 '22 at 14:03