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

Viewed 464

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?

1 Answers

Found a solution. The problem was that rubocop amended the 42 line in /bin/bundle file to return gemfile if gemfile.present?, which through the error. I just revert it to the initial state of return gemfile if gemfile && !gemfile.empty? and everything worked. Hope, that will help someone.

Related