Fixing could not detect rake tasks issue with bundler-2.2.3 when deploying to Heroku

Recently I tried deploying a rails 6 app bundled with bundler-2.2.3 but I ran into some annoying error, check it out;

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_7ae026de_/config/boot.rb:4:in `require': cannot load such file -- bootsnap/setup (LoadError)!     from /tmp/build_7ae026de_/config/boot.rb:4:in `<top (required)>'!     from /tmp/build_7ae026de_/bin/rake:3:in `require_relative'!     from /tmp/build_7ae026de_/bin/rake:3:in `<main>'

After searching around for a while, I couldn’t find a solution that worked for me. Then I saw here: https://devcenter.heroku.com/articles/bundler-version#bundler-2-2-3, that there was some known issue that a Gemfile.lock file generated with Bundler 2.2.3 locally may not work on Heroku unless the Linux platform is explicitly “locked”.

I spent some time trying to uninstall bundler 2.2.3 and install an older bundler version but it wasn’t very successful because gem 2.2.3 got bundled as the default bundler and so I ran into this error while trying to do that:

Gem bundler-2.2.3 cannot be uninstalled because it is a default gem

Okay let’s talk about my solution:

My solution was to figure out a way to uninstall this bundler and install a lower version that works well on heroku, so I can enjoy my weekend.

Step 1: Find the gempath of the bundler, to do this, run:

~ gem env gempath

I got the gemfile path after running this, it looked like this:

/Users/username/.rvm/gems/ruby-2.7.2:/Users/username/.rvm/rubies/ruby-2.7.2/lib/ruby/gems/2.7.0

Step 2: Open up the file, I opened this file manually, by `command+click `on it from the terminal.

I looked into the *specifications/default* folder and there it was, bundler-2.2.3.gemspec. for me I manually deleted this file, you could do same from the terminal.

To confirm that bundler-2.2.3 was no longer there, I ran `gem list bundler ` and it wasn’t on the list anyway. Whooo, okay that was a relief!!!.

Step 3: Install a lower version of the bundler gem

To install a lower version of the bundler gem, run:

~ gem install bundler -v 2.1.4

To confirm that bundler 2.1.4 has been added as a default bundler, run:

~ gem list bundler

You should see `bundler-2.1.4` listed as one of the versions, run:

~ bundle install

your app will now be bundled with bundler-2.1.4 which is a version that works well with Heroku.

After going through all these steps, I tried deploying to Heroku again and voila..🎉 🎉 it was successful.

Thanks for reading, I hope this post helps someone in fixing a similar issue.

Fullstack developer/ Ruby on Rails/Javascript