首页 > 解决方案 > Heroku 在运行 `bundle install` 时使用较旧的 Ruby 版本

问题描述

我正在尝试在 Heroku 上的 Ruby 2.7.1 上运行 Rails 应用程序。一切正常,然后我在 Gemfile 中更改了一些内容以使用Ruby 2.7 的编号参数,现在部署失败并显示以下错误消息:

remote: -----> Build succeeded!
remote: -----> Ruby app detected
remote: -----> Installing bundler 2.0.2
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Compiling Ruby/Rails
remote:
remote:  !
remote:  !     There was an error parsing your Gemfile, we cannot continue
remote:  !
remote:  !     [!] There was an error parsing `Gemfile`: Undefined local variable or method `_1' for Gemfile. Bundler cannot continue.
remote:  !
remote:  !     #  from /tmp/build_6681cf5c/Gemfile:22
remote:  !     #  -------------------------------------------
remote:  !     #  dependencies.any? { _1.name == gem_name }
remote:  !     #  -------------------------------------------
remote:  !     . Bundler cannot continue.

它在本地运行良好,我一直在其他几个 Rails 应用程序中使用相同的代码,部署从来都不是问题。

由于该错误Undefined local variable or method '_1' for Gemfile.,我假设运行时使用了 < 2.7 的 Ruby 版本bundle install。该应用程序本身在 Ruby 2.7.1 上运行良好:

$ heroku run "ruby -v"
Running ruby -v on ⬢ myapp... up, run.7979 (Free)
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]

这里还有一些其他类似的问题,但它们都处理 Heroku 不尊重 Gemfile 或 .ruby-version 中设置的 Ruby 版本,这对我来说不是问题,只是在bundle install它似乎使用不同的 Ruby 版本一些原因...

有没有办法进一步调试,或者即使在bundle install部署期间也强制使用 Ruby 2.7?

标签: ruby-on-railsrubyherokuruby-2.7

解决方案


推荐阅读