Alex Riabukha
Alex Riabukha

Reputation: 307

Heroku bundler undefined method "present?", fails to install gems via bundler

Encountered a weird error while trying to push the rails app to Heroku:

    remote: -----> Building on the Heroku-20 stack
    remote: -----> Using buildpack: heroku/ruby
    remote: -----> Ruby app detected
    remote: -----> Installing bundler 2.2.16
    remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
    remote: -----> Compiling Ruby/Rails
    remote: -----> Using Ruby version: ruby-3.0.1
    remote: -----> Installing dependencies using bundler 2.2.16
    remote:        Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
    remote:        /tmp/build_ae8e646d/bin/bundle:42:in `gemfile': undefined method `present?' for "/tmp/build_ae8e646d/Gemfile":String (NoMethodError)
    remote:        Did you mean?  prepend
    remote:         from /tmp/build_ae8e646d/bin/bundle:49:in `lockfile'
    remote:         from /tmp/build_ae8e646d/bin/bundle:57:in `lockfile_version'
    remote:         from /tmp/build_ae8e646d/bin/bundle:68:in `bundler_version'
    remote:         from /tmp/build_ae8e646d/bin/bundle:72:in `bundler_requirement'
    remote:         from /tmp/build_ae8e646d/bin/bundle:100:in `activate_bundler'
    remote:         from /tmp/build_ae8e646d/bin/bundle:88:in `load_bundler!'
    remote:         from /tmp/build_ae8e646d/bin/bundle:116:in `<main>'
    remote:        Bundler Output: /tmp/build_ae8e646d/bin/bundle:42:in `gemfile': undefined method `present?' for "/tmp/build_ae8e646d/Gemfile":String (NoMethodError)
    remote:        Did you mean?  prepend
    remote:         from /tmp/build_ae8e646d/bin/bundle:49:in `lockfile'
    remote:         from /tmp/build_ae8e646d/bin/bundle:57:in `lockfile_version'
    remote:         from /tmp/build_ae8e646d/bin/bundle:68:in `bundler_version'
    remote:         from /tmp/build_ae8e646d/bin/bundle:72:in `bundler_requirement'
    remote:         from /tmp/build_ae8e646d/bin/bundle:100:in `activate_bundler'
    remote:         from /tmp/build_ae8e646d/bin/bundle:88:in `load_bundler!'
    remote:         from /tmp/build_ae8e646d/bin/bundle:116:in `<main>'
    remote: 
    remote:  !
    remote:  !     Failed to install gems via Bundler.
    remote:  !
    remote:  !     Push rejected, failed to compile Ruby app.

Before that, I’ve deployed a scaffold of the app to Heroku and everything went fine. But after working some time and pushing changes that error appeared.

Have already tried regenerating Gemlock.file and bundle update but without luck. Locally, everything works fine. Ruby and bundler versions are the same locally and on Heroku. Now, don’t have a clue, what that could be. Have anyone encountered such an error?

Upvotes: 6

Views: 1065

Answers (2)

Alex Riabukha
Alex Riabukha

Reputation: 307

Found a solution. The problem was that rubocop amended line 42 in the /bin/bundle file to return gemfile if gemfile.present?, which threw the error.

I just reverted it to the initial state of return gemfile if gemfile && !gemfile.empty? and everything worked.

Hope, that will help someone.

Upvotes: 18

Robert Head
Robert Head

Reputation: 603

The root cause of this is an autofix made by rubocop's Rails/Present cop.

You can solve this and prevent it from returning by changing bin/bundle line 42 (ish) from: return gemfile if gemfile && !gemfile.empty? to: return gemfile if gemfile && !gemfile.empty? # rubocop:disable Rails/Present

OR

Exclude the file in your .rubocop.yml file:

AllCops:
  NewCops: enable
  Exclude:
    - bin/bundle

Upvotes: 0

Related Questions