Heroku 捆绑器未定义方法“存在?”,无法通过捆绑器安装 gem

Ale*_*kha 6 ruby-on-rails heroku bundler

尝试将 Rails 应用推送到 Heroku 时遇到奇怪的错误:

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

在此之前,我\xe2\x80\x99已经将应用程序的脚手架部署到Heroku,一切都很顺利。但经过一段时间的工作并推动更改后,出现了错误。

\n

已经尝试重新生成 Gemlock.file 和捆绑更新,但没有运气。在本地,一切正常。Ruby 和捆绑器版本在本地和 Heroku 上是相同的。现在,don\xe2\x80\x99t 不知道那可能是什么。有人遇到过这样的错误吗?

\n

Ale*_*kha 18

找到了解决方案。问题是 rubocop 将 /bin/bundle 文件中的 42 行修改为return gemfile if gemfile.present?,从而导致错误。我只是将其恢复到初始状态return gemfile if gemfile && !gemfile.empty?,一切正常。希望这会对某人有所帮助。