这个问题与this one有关,但建议的解决方案对我不起作用。
我正在尝试使用Rails 5.2
部署Ruby 2.6.1
应用程序,但我在部署阶段一直收到此错误:
/app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/lockfile_parser.rb:108:in `warn_for_outdated_bundler_version': You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError)
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/lockfile_parser.rb:95:in `initialize'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/definition.rb:83:in `new'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/definition.rb:83:in `initialize'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/dsl.rb:234:in `new'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/dsl.rb:234:in `to_definition'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/dsl.rb:13:in `evaluate'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/definition.rb:34:in `build'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler.rb:135:in `definition'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler.rb:101:in `setup'
from /app/vendor/ruby-2.6.1/lib/ruby/2.6.0/bundler/setup.rb:20:in `<top (required)>'
from /app/vendor/ruby-2.6.1/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /app/vendor/ruby-2.6.1/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /app/config/boot.rb:3:in `<top (required)>'
from /app/bin/rake:2:in `require_relative'
from /app/bin/rake:2:in `<main>'
我在这个错误中发现奇怪的是这一行:
/app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/lockfile_parser.rb:108:in `warn_for_outdated_bundler_version': You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError)
Heroku似乎说它正在使用Ruby 2.6.0
。但是在构建阶段,它说它使用Ruby 2.6.1
和Bundler 2
:
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.6.1
-----> Installing dependencies using bundler 2.0.1
构建成功,但部署失败。
以下是如何配置我的应用程序。
Gemfile(简化为重要的)
ruby "2.6.1"
gem 'rails', '~> 5.2'
Gemfile.lock(简化为重要的)
RUBY VERSION
ruby 2.6.1p33
BUNDLED WITH
2.0.1
在heroku上,我的buildpack是heroku/ruby
。我的筹码是heroku-18
。
如Bundler 2
所说,Heroku似乎支持this post。
有关部署失败的想法吗?
我找到了解决方案。问题出在部署时,而不是在构建期间。部署使用Ruby 2.6.0,因为默认情况下Heroku的web dyno:
rails server -p $PORT -e $RAILS_ENV
然而,this post from bundler github告诉每个命令加上bundle exec
的前缀。但来自dyno的rails server
命令没有前缀。
我找到的解决方法是修改项目Procfile
文件,并添加以下行:
web: bundle exec rails server -p $PORT -e $RAILS_ENV
这样,rails server
命令使用预期的Ruby version
,生成错误的2.6.1
的2.6.0
insteand。