我正在尝试将非常基本的Rails应用程序部署到全新的Heroku应用程序中。我将Heroku应用程序连接到GitHub存储库并触发了第一次部署。 Heroku无法构建应用,因为“激活捆绑程序(2.0.1)失败”。
这是构建日志,其中的错误用!
突出显示,为简洁起见[...]
隐藏了一些部分:
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.6.3
-----> Installing dependencies using bundler 2.0.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
[...]
Bundle complete! 17 Gemfile dependencies, 59 gems now installed.
[...]
Bundle completed (47.25s)
Cleaning up the bundler cache.
-----> Installing node-v10.15.3-linux-x64
-----> Installing yarn-v1.16.0
-----> Detecting rake tasks
!
! Could not detect rake tasks
! ensure you can run `$ bundle exec rake -P` against your app
! and using the production group of your Gemfile.
! Activating bundler (2.0.1) failed:
! Could not find 'bundler' (2.0.1) required by your /tmp/build_19c87a31c0181b0ad80a21cb76d32d96/Gemfile.lock.
! To update to the latest version installed on your system, run `bundle update --bundler`.
! To install the missing version, run `gem install bundler:2.0.1`
! Checked in 'GEM_PATH=/tmp/build_19c87a31c0181b0ad80a21cb76d32d96/vendor/bundle/ruby/2.6.0', execute `gem env` for more information
!
! To install the version of bundler this project requires, run `gem install bundler -v '2.0.1'`
!
[...]
! Push rejected, failed to compile Ruby app.
! Push failed
我按照错误消息中的说明进行操作,但并不能解决问题:
! ensure you can run `$ bundle exec rake -P` against your app
! and using the production group of your Gemfile.
$ bundle exec rake -P
[...] # long output, but yes, I can run it.
$ RAILS_ENV=production bundle exec rake -P
[...] # long output, but again I can run it.
! Activating bundler (2.0.1) failed:
! Could not find 'bundler' (2.0.1) required by your /tmp/build_19c87a31c0181b0ad80a21cb76d32d96/Gemfile.lock.
! To update to the latest version installed on your system, run `bundle update --bundler`.
! To install the missing version, run `gem install bundler:2.0.1`
# I'm already using bundler 2.0.1:
$ bundler --version
Bundler version 2.0.1
Heroku says it supports bundler 2.X:
Ruby构建包现在将检查Gemfile.lock的内容,并使用基于BUNDLED WITH声明的捆绑程序版本。
我的Gemfile.lock指定BUNDLED WITH 2.0.1:
GEM
remote: https://rubygems.org/
specs: [...]
PLATFORMS
ruby
DEPENDENCIES
[...]
RUBY VERSION
ruby 2.6.3p62
BUNDLED WITH
2.0.1
我应该解决什么?
答案 0 :(得分:0)
我通过反复试验找到了解决方案。我从构建日志中考虑了以下几行:
-----> Installing dependencies using bundler 2.0.2
[...]
! Activating bundler (2.0.1) failed:
! Could not find 'bundler' (2.0.1) required by your /tmp/build_19c87a31c0181b0ad80a21cb76d32d96/Gemfile.lock.
Heroku使用捆绑程序2.0.2,我最初认为它可以安装2.0.1 Gemfile.lock。事实并非如此。我删除了Gemfile.lock,安装了bundler 2.0.2,并用它再次捆绑:
rm Gemfile.lock
gem install bundler
bundle --version # Make sure the output is 2.0.2
bundle install
此重新生成的Gemfile.lock现在BUNDLED WITH 2.0.2
,因此我能够成功地部署到Heroku。