Heroku Bundler版本更新移除已安装gem致应用部署编译失败
Heroku部署失败:Bundler升级导致mini_portile2被移除
我有一个正常运行的ROR Heroku应用,平时定期上传代码变更。最近仅修改了少量CSS,没碰过Gemfile和Gemfile.lock,本地编译运行完全正常,但部署时Heroku自动把Bundler从2.3.10升级到2.3.25,导致编译失败。对比日志发现新版Bundler移除了mini_portile2 (2.6.1),但有其他gem依赖这个包,而且它明明已经在Gemfile和Gemfile.lock里了。试过删除重新生成Gemfile.lock、升级mini_portile2版本,都没解决。
上次成功部署日志
-----> Using buildpack: heroku/ruby -----> Ruby app detected -----> Installing bundler 2.3.10 -----> Removing BUNDLED WITH version in the Gemfile.lock -----> Compiling Ruby/Rails -----> Using Ruby version: ruby-2.7.1 -----> Installing dependencies using bundler 2.3.10 Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4 Using rake 13.0.6 Using concurrent-ruby 1.1.9 Using i18n 1.8.10 Using minitest 5.14.4 Using tzinfo 2.0.4 Using zeitwerk 2.4.2 Using activesupport 6.1.3.2 Using builder 3.2.4 Using erubi 1.10.0 Using mini_portile2 2.6.1 Using racc 1.5.2 ..... Bundle complete! 39 Gemfile dependencies, 132 gems now installed. Gems in the groups 'development' and 'test' were not installed. Bundled gems are installed into `./vendor/bundle` Bundle completed (0.88s) Cleaning up the bundler cache. -----> Installing node-v16.13.1-linux-x64 -----> Installing yarn-v1.22.17 -----> Detecting rake tasks -----> Preparing app for Rails asset pipeline Running: rake assets:precompile
本次失败部署日志
-----> Building on the Heroku-18 stack remote: -----> Using buildpack: heroku/ruby remote: -----> Ruby app detected remote: -----> Installing bundler 2.3.25 remote: -----> Removing BUNDLED WITH version in the Gemfile.lock remote: -----> Compiling Ruby/Rails remote: remote: ###### WARNING: remote: remote: Your app was upgraded to bundler 2.3.25. remote: Previously you had a successful deploy with bundler 2.3.10. remote: remote: remote: -----> Using Ruby version: ruby-2.7.1 remote: -----> Installing dependencies using bundler 2.3.25 remote: Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4 remote: Using rake 13.0.6 remote: Using concurrent-ruby 1.1.9 remote: Using i18n 1.8.10 remote: Using minitest 5.14.4 remote: Using tzinfo 2.0.4 remote: Using zeitwerk 2.4.2 remote: Using activesupport 6.1.3.2 remote: Using builder 3.2.4 remote: Using erubi 1.10.0 remote: Using racc 1.5.2 ..... remote: Bundle complete! 39 Gemfile dependencies, 131 gems now installed. remote: Gems in the groups 'development' and 'test' were not installed. remote: Bundled gems are installed into `./vendor/bundle` remote: Bundle completed (0.69s) remote: Cleaning up the bundler cache. remote: Removing bundler (2.3.10) remote: Removing mini_portile2 (2.6.1) remote: -----> Installing node-v16.18.1-linux-x64 remote: -----> Installing yarn-v1.22.19 remote: -----> Detecting rake tasks remote: remote: ! remote: ! Could not detect rake tasks remote: ! ensure you can run `$ bundle exec rake -P` against your app remote: ! and using the production group of your Gemfile. remote: ! /tmp/build_5db96fd8/vendor/ruby-2.7.1/lib/ruby/2.7.0/bundler/spec_set.rb:86:in `block in materialize': Could not find mini_portile2-2.7.0 in any of the sources (Bundler::GemNotFound)
解决方案
1. 锁定Bundler版本
既然旧版本Bundler能正常部署,直接在项目里锁定版本避免Heroku自动升级:
- 本地运行:
bundle lock --add-platform x86_64-linux(确保Gemfile.lock包含Linux平台依赖) - 在项目根目录创建
.bundle/config文件,写入:BUNDLED WITH: 2.3.10 - 或者在Gemfile里显式指定:
gem 'bundler', '2.3.10' - 提交所有变更后重新部署。
2. 显式指定mini_portile2版本
错误提示找不到2.7.0版本,但你的依赖实际需要2.6.1,直接在Gemfile里强制指定:
- 添加:
gem 'mini_portile2', '2.6.1' - 运行
bundle install更新Gemfile.lock - 提交Gemfile和Gemfile.lock后重新部署。
3. 清理Heroku缓存
缓存可能导致依赖异常,部署前先清理:
heroku repo:purge_cache -a your-app-name
再推送代码重新部署。
内容的提问来源于stack exchange,提问作者Idb
相关产品推荐
相关产品推荐

