我收到错误:
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)但没有解决方案?
最佳答案
[我已编辑此原始回复以包含解决方案]
我也遇到了这个问题,并且有 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
中,但这没有任何区别,预编译 Assets 也没有什么区别。其他注意事项:
- 所有 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
在对此答案的评论中,OP 指出:
Because Bundler version 2.2.10 was installed for me as the "default" I hadnt realised Gem bundler-2.1.4 cannot be uninstalled via gem uninstall bundler Using the cleanup_bundler script documented here enabled me to downgrade to v2.1.4 properly. This then did fix the rake problem.
$ gem uninstall bundler
=> Gem bundler-2.2.10 cannot be uninstalled because it is a default gem
StackOverflow 更喜欢内联答案,而不是外部链接,因为外部链接可能会损坏,因此再次指出,功劳归于上面链接的文章:
From all the references I can find, the only way to remove it is to delete the
bundler-2.1.4.gemspec
file from the gem path. The following commands did the trick for me [...] I wrote a script for you:#!/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
- 这可能会解决问题。
关于ruby-on-rails - Heroku 部署 - 无法加载此类文件 - rake (LoadError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66170853/