在尝试将rails应用推送到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.
在此之前,我已经将应用程序的脚手架部署到Heroku,一切都很顺利。但在工作了一段时间并推动更改后,错误出现了。
已经尝试过重新生成Gemlock.file和bundle更新,但没有成功。在当地,一切都很好。Ruby和bundler版本在本地和Heroku上是相同的。现在,我不知道,那会是什么。有人遇到过这样的错误吗?
2条答案
按热度按时间aydmsdu91#
找到解决办法了。问题是rubocop将/bin/bundle文件中的42行修改为
return gemfile if gemfile.present?
,这导致了错误。我只是将它恢复到return gemfile if gemfile && !gemfile.empty?
的初始状态,一切都正常。希望这能帮到别人。qxsslcnc2#
根本原因是rubocop的Rails/Present cop所做的自动修复。
您可以解决此问题,并通过将bin/bundle行42(ish)从以下位置更改为阻止其返回:
return gemfile if gemfile && !gemfile.empty?
至:return gemfile if gemfile && !gemfile.empty? # rubocop:disable Rails/Present
或
排除.rubocop.yml文件中的文件: