Rails 部署到 Heroku 时出现抽成问题

Rails rake issue when deploying to Heroku

解决方案:我 运行ning ruby 2.6.6p146 与 Bundler 版本 2.2.4。根据@thiebo 的建议,我降级到 Bundler 2.1.2 并且成功了!步骤:

  1. $ gem 卸载捆绑器
  2. [然后删除Gemfile.lock]
  3. $ gem 安装捆绑器 --version '2.1.2'

我已经尝试了这些选项,但没有任何效果:

我确实可以 运行 bundle exec rake -P against my app

我尝试拯救 Rakefile,并在我的 Gemfile 中将 rspec 投入生产:

我在 gem 文件中添加了 'rake'。

尝试添加 gem 'rack-timeout':

我也关注了这个帖子,但无济于事:https://github.com/rubygems/bundler/issues/3640

这是错误:

Bundle completed (36.93s)
Cleaning up the bundler cache.
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.
!     
[...] rubygems_integration.rb:460:in `block in replace_bin_path': can't find executable rake for gem rake. rake is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception) from /[...]ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/rubygems_integration.rb:491:in `block in replace_bin_path' from ./vendor/bundle/bin/rake:29:in `<main>'
![...]helpers/rake_runner.rb:106:in `load_rake_tasks!': Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)
ensure you can run `$ bundle exec rake -P` against your app
and using the production group of your Gemfile.
/tmp/build_dcccbbf6_/vendor/bundle/ruby/2.6.0/gems/bundler- 
2.0.2/lib/bundler/rubygems_integration.rb:460:in `block in replace_bin_path': can't find executable rake for gem rake. rake is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)
from /tmp/build_dcccbbf6_/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/rubygems_integration.rb:491:in `block in replace_bin_path'
from ./vendor/bundle/bin/rake:29:in `<main>'
from /tmp/codon/tmp/buildpacks/63cff2a36c882a48324b4b7a5466efcada2e529a/lib/language_pack/ruby.rb:1035:in `rake'
from /tmp/codon/tmp/buildpacks/63cff2a36c882a48324b4b7a5466efcada2e529a/lib/language_pack/rails4.rb:84:in `block (2 levels) in run_assets_precompile_rake_task'
from /tmp/codon/tmp/buildpacks/63cff2a36c882a48324b4b7a5466efcada2e529a/lib/language_pack/base.rb:190:in `log'
from /tmp/codon/tmp/buildpacks/63cff2a36c882a48324b4b7a5466efcada2e529a/lib/language_pack/rails4.rb:78:in `block in run_assets_precompile_rake_task'
from /tmp/codon/tmp/buildpacks/63cff2a36c882a48324b4b7a5466efcada2e529a/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
from /tmp/codon/tmp/buildpacks/63cff2a36c882a48324b4b7a5466efcada2e529a/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
from /tmp/codon/tmp/buildpacks/63cff2a36c882a48324b4b7a5466efcada2e529a/lib/language_pack/instrument.rb:17:in `block in instrument'
from /tmp/tmp.9BjaQ6WXw6/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
from /tmp/codon/tmp/buildpacks/63cff2a36c882a48324b4b7a5466efcada2e529a/lib/language_pack/instrument.rb:16:in `instrument'
from /tmp/codon/tmp/buildpacks/63cff2a36c882a48324b4b7a5466efcada2e529a/lib/language_pack/base.rb:50:in `instrument'
from /tmp/codon/tmp/buildpacks/63cff2a36c882a48324b4b7a5466efcada2e529a/lib/language_pack/base.rb:46:in `instrument'
from /tmp/codon/tmp/buildpacks/63cff2a36c882a48324b4b7a5466efcada2e529a/lib/language_pack/rails4.rb:77:in `run_assets_precompile_rake_task'
from /tmp/codon/tmp/buildpacks/63cff2a36c882a48324b4b7a5466efcada2e529a/lib/language_pack/ruby.rb:111:in `block (2 levels) in compile'
from /tmp/codon/tmp/buildpacks/63cff2a36c882a48324b4b7a5466efcada2e529a/lib/language_pack/ruby.rb:1056:in `allow_git'
from /tmp/codon/tmp/buildpacks/63cff2a36c882a48324b4b7a5466efcada2e529a/lib/language_pack/ruby.rb:104:in `block in compile'
from /tmp/codon/tmp/buildpacks/63cff2a36c882a48324b4b7a5466efcada2e529a/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
from /tmp/codon/tmp/buildpacks/63cff2a36c882a48324b4b7a5466efcada2e529a/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
from [... a lot more lines like this]
! Push rejected, failed to compile Ruby app.
! Push failed

非常感谢,如果有人知道的话。

简答

使用 Heroku 支持的捆绑器版本

  gem uninstall bundler
  gem install bundler --version '2.1.2'

  rm Gemfile.lock
  bundle install

  git add Gemfile.lock
  git commit -m "downgrade bundler to appease the Heroku gods"
  git push heroku

这个问题好像以前发生过:https://github.com/rubygems/bundler/issues/7486

我刚遇到这个问题,official documentation worked 对我来说:

Bundler 2.2.3+

An app’s Gemfile.lock that is generated with Bundler 2.2.3 locally may not work on Heroku unless the Linux platform is explicitly “locked”:

$ bundle lock --add-platform ruby
$ bundle lock --add-platform x86_64-linux
$ bundle install
$ git add . ; git commit -m "Bundler fix"