【问题标题】:Heroku deployment - cannot load such file -- rake (LoadError)Heroku 部署 - 无法加载此类文件 - rake (LoadError)
【发布时间】:2021-05-16 03:29:18
【问题描述】:

我得到错误:

remote:  !     Could not detect rake tasks
 
04:36
 
remote:  !     ensure you can run `$ bundle exec rake -P` against your app
 
04:36
 
remote:  !     and using the production group of your Gemfile.
 
04:36
 
remote:  !     /tmp/build_aa020f9e/bin/rake:8:in `require': cannot load such file -- rake (LoadError)
 
04:36
 
remote:  !     from /tmp/build_aa020f9e/bin/rake:8:in `<main>'

从 Codeship 运行 Heroku 部署管道时

/bin/rake 是这样的

#!/usr/bin/env ruby
begin
  load File.expand_path('../spring', __FILE__)
rescue LoadError => e
  raise unless e.message.include?('spring')
end
require_relative '../config/boot'
require 'rake'
Rake.application.run

所以第 8 行需要 'rake'

我尝试将 gem rake 显式添加到我的 gemfile 中

然后因为提到生产组我尝试了

group :production do
  gem 'rake'
end

这些都不起作用,所以我的代码推送被 Heroku 拒绝了

remote:  !     Push rejected, failed to compile Ruby app.
 
04:36
 
remote: 
 
04:36
 
remote:  !     Push failed

有什么想法吗?我在 StackOverflow rails cannot load such file -- rake (LoadError) 上看到了类似的帖子,但没有解决方案?

【问题讨论】:

  • 尝试使用 bundle exec command_to_be_executed,比如 bundle exec sidekiq。
  • Push rejected, failed to compile Ruby app. 查看build.log 编译 Ruby 应用程序失败的原因。
  • 感谢大家的回复,但失败的是 git push heroku a)我看不到我可以“捆绑执行”这个命令,b)我已经从 build.log 发布了错误。由于以下错误,Ruby 应用程序无法构建:/tmp/build_aa020f9e/bin/rake:8:in `require': cannot load such file -- rake (LoadError) from require 'rake' in bin/rake

标签: ruby-on-rails heroku deployment rake


【解决方案1】:

[我已编辑此原始回复以包含解决方案]

我也有这个确切的问题,与 Heroku 的开放票。 目前还没有回复,很遗憾,但我通过 Google 的幸运命中在其他地方找到了答案。

上下文,供日后参考和搜索引擎

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_b8f358ab/bin/rake:3:in `require': cannot load such file -- rake (LoadError)
remote:  !     from /tmp/build_b8f358ab/bin/rake:3:in `<main>'
remote:  !
remote: /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/helpers/rake_runner.rb:106:in `load_rake_tasks!': Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)
remote: ensure you can run `$ bundle exec rake -P` against your app
remote: and using the production group of your Gemfile.
remote: /tmp/build_b8f358ab/bin/rake:3:in `require': cannot load such file -- rake (LoadError)
remote:     from /tmp/build_b8f358ab/bin/rake:3:in `<main>'

正如您无疑已经发现的那样,上面建议的bundle exec rake -P 命令适用于本地的任何Rails.env 设置。我也尝试将rake 明确添加到Gemfile,但这没有任何区别,预编译资产也没有。其他注意事项:

  • 所有 gem 构建成功
  • 此部署将提示并从 Heroku-18 更新到 Heroku-20 平台;你的呢?
  • Rails 5 最新补丁,但 Rails 6 还没有
  • Ruby 2.7.2

我不使用 Spring,所以我的 bin/rake 更简单:

#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run

...与您的更复杂的代码一样,肯定是 require 'rake' 失败了。

解决方案

我不能相信 - 这是这个答案:

...解决了,只需要从 2.1.2 更改为 2.1.4。复制粘贴上述解决方案 - 这又不是我的工作,功劳属于上面的 OP

gem uninstall bundler
gem install bundler --version '2.1.4' # If this doesn't work - see below

rm Gemfile.lock
bundle install

git add Gemfile.lock
git commit -m "Downgrade Bundler to match current Heroku version, so that deployments succeed"
git push heroku

这解决了我的问题。看起来像一个完全奇怪的解决方案,但你去吧。

如果您似乎无法降级 Bundler

在这个答案的 cmets 中,OP 指出:

因为 Bundler 版本 2.2.10 为我安装为“默认”,所以我没有意识到无法通过 gem uninstall bundler 卸载 Gem bundler-2.1.4 使用 cleanup_bundler 脚本 documented here 使我能够正确降级到 v2.1.4 .这确实解决了 rake 问题。

$ gem uninstall bundler
=> Gem bundler-2.2.10 cannot be uninstalled because it is a default gem

StackOverflow 更喜欢内联而不是外部链接的答案,因为外部链接可能会中断,所以再次指出,归功于上面链接的文章

从我能找到的所有参考资料中,删除它的唯一方法是从 gem 路径中删除 bundler-2.1.4.gemspec 文件。以下命令对我有用 [...] 我为您编写了一个脚本:

#!/usr/bin/env ruby

gempaths = `gem env gempath`.split(":")
gempaths.each do |gempath|
  # lookup bundler-*.gemspec files and delete them
  # this is the only way to completely cleanup default bundler
  # Note: the bundler gemspecs' paths are different for CRuby and JRuby
  Dir.glob(gempath.strip + "/specifications/**/bundler-*.gemspec").each { |p| File.delete(p) }
end

# Remember to make this file executable

...所以希望如果您将其保存为 .rb 文件方便的地方,chmod u+x foo.rb./foo.rb - 这可能会解决问题。

【讨论】:

  • 感谢安德鲁的帖子。我什至无法弄清楚如何向 Heroku 放置支持票?当我单击“创建票证”按钮时,它只会让我回到帮助页面。我正在使用 Ruby 2.7.2 和 Rails 6.1.2 在跟踪的更下方,我得到了与 run_assets_precompile_rake_task 相关的错误,所以我认为这与 Webpacker 和与资产相关的节点安装有关,但我才刚刚开始尝试在devcenter.heroku.com/articles/… 的帮助下探索这一点,我会让你知道我的进展。
  • 已经过去一天多了,除了一封自动电子邮件说他们只在美国工作时间看他们之外,他们甚至没有确认票证。我不认为你错过了很多! :-/
  • 希望您能尽快收到他们的回复。我真的有一种感觉,就是这个失败了,但还没有解决方案:devcenter.heroku.com/articles/… 作为编译阶段的最后一项任务,如果您定义了 assets:precompile Rake 任务,则会执行 assets:precompile Rake 任务,并且没有 public/assets/manifest-*.json 文件。这将编译所有资产并将它们放在您的公共目录中。如果 rake 检测或资产编译任务失败,部署也会失败。有关更多信息,请参阅 Heroku 上的 Rails 资产管道。
  • 是的,除了我已经尝试过预编译(添加清单等)并且它以同样的方式失败。我们看到的失败并不是 Heroku 资产编译问题更广泛记录的常见失败。出于兴趣,您使用的是什么 Rails 版本,这是针对 Heroku-18 环境的 Heroku-20,还是您在 Heroku-18 上,并且此部署是导致 Heroku-20 更新的事件?
  • 正确 - 在我的案例中找到了解决方案 - 请参阅上面的编辑答案,并请注意stackoverflow.com/a/65604896 的原始答案,所以如果没有其他问题,请给予支持。希望它也对你有用 - 祈祷。
【解决方案2】:

我刚遇到这个问题,Heroku 似乎在official documentation 中添加了一个对我有用的部分:

捆绑器 2.2.3+

除非 Linux 平台被明确“锁定”,否则使用 Bundler 2.2.3 在本地生成的应用程序 Gemfile.lock 可能无法在 Heroku 上运行:

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

【讨论】:

    猜你喜欢
    • 2015-03-20
    • 2021-04-08
    • 1970-01-01
    • 2023-03-30
    • 2019-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多