简体   繁体   English

Heroku 部署 - 无法加载此类文件 — rake (LoadError)

[英]Heroku deployment - cannot load such file — rake (LoadError)

I get the error:我得到错误:

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>'

when running a Heroku deployment pipeline from Codeship从 Codeship 运行 Heroku 部署管道时

/bin/rake looks like this /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

so line 8 is require 'rake'所以第8行需要'rake'

I tried adding gem rake explicitly to my gemfile我尝试将 gem rake 明确添加到我的 gemfile

Then because production group is mentioned I tried然后因为提到了生产组,我尝试了

group :production do
  gem 'rake'
end

None of this works and so my code push is rejected by Heroku这些都不起作用,所以我的代码推送被 Heroku 拒绝

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

Any ideas anyone?I see a similar post on StackOverflow rails cannot load such file -- rake (LoadError) but without a solution?有什么想法吗?我在 StackOverflow rails 上看到类似的帖子无法加载此类文件——rake (LoadError)但没有解决方案?

[I've edited this original response to include a solution] [我已编辑此原始回复以包含解决方案]

I have this exact issue too, with an open ticket with Heroku.我也有这个确切的问题,有一张带有 Heroku 的公开票。 No response yet, sadly but I found an answer elsewhere via a lucky hit in Google.遗憾的是,还没有回应,但我通过谷歌的幸运命中在其他地方找到了答案。

Context, for future reference and search engines上下文,供将来参考和搜索引擎

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>'

As you've doubtless already found, the suggested bundle exec rake -P command above works fine with any Rails.env setting locally.正如您无疑已经发现的那样,上面建议的bundle exec rake -P命令适用于本地的任何Rails.env设置。 I, too, tried adding rake to Gemfile explicitly but this made no difference, nor did precompiling assets.我也尝试将rake显式添加到Gemfile ,但这没有任何区别,预编译资产也没有。 Other things to note:其他需要注意的事项:

  • All gems build successfully所有宝石都成功构建
  • This deploy would prompt and update from Heroku-18 to the Heroku-20 platform;此部署将提示并从 Heroku-18 更新到 Heroku-20 平台; does yours?你的呢?
  • Rails 5 latest patch, but not Rails 6 yet Rails 5 最新补丁,但还不是 Rails 6
  • Ruby 2.7.2 Ruby 2.7.2

I don't use Spring so my bin/rake is simpler:我不使用 Spring 所以我的bin/rake更简单:

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

...and as with your more complex code, it's definitely the require 'rake' that fails. ...与您更复杂的代码一样,肯定是失败的require 'rake'

Solution解决方案

I can't take credit - it's this answer:我不能相信 - 这是这个答案:

...that solved it, only you need to change from 2.1.2 to 2.1.4. ...解决了它,只需要从 2.1.2 更改为 2.1.4。 Copy-pasting the above solution - again this is not my work, the credit belongs to the OP above :复制粘贴上述解决方案 -这又不是我的工作,功劳属于上面的 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

This has solved the issue in my case.这解决了我的问题。 Seems like an utterly bizarre solution, but there you go.似乎是一个非常奇怪的解决方案,但是你有 go。

If you don't seem to be unable to downgrade Bundler如果您似乎无法降级 Bundler

In the comments on this answer, the OP notes:在对此答案的评论中,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.因为 Bundler 版本 2.2.10 是为我安装的“默认”,所以我没有意识到无法通过 gem uninstall bundler 卸载 Gem bundler-2.1.4 使用此处记录的 cleanup_bundler 脚本使我能够正确降级到 v2.1.4。 This then did fix the rake problem.这确实解决了 rake 问题。

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

StackOverflow prefer answers to be inline rather than linked externally as external links can break, so once again noting that credit goes to the article linked above : 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.从我能找到的所有参考资料中,删除它的唯一方法是从 gem 路径中删除bundler-2.1.4.gemspec文件。 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

...so hopefully if you save that as a .rb file somewhere convenient, chmod u+x foo.rb and ./foo.rb - that might solve the problem. ...所以希望如果您将其保存为.rb文件方便的地方, chmod u+x foo.rb./foo.rb - 这可能会解决问题。

I just had this problem and Heroku seems to have added a section to the official documentation that worked for me:我刚遇到这个问题,Heroku 似乎在官方文档中添加了一个对我有用的部分:

Bundler 2.2.3+捆绑器 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”:使用 Bundler 2.2.3 在本地生成的应用程序 Gemfile.lock 可能无法在 Heroku 上运行,除非 Linux 平台被明确“锁定”:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Heroku无法检测到rake任务(LoadError:无法加载此类文件 - rspec / core / rake_task) - Heroku could not detect rake tasks (LoadError: cannot load such file — rspec/core/rake_task) 耙子流产了! LoadError:无法加载此类文件— httparty - rake aborted! LoadError: cannot load such file — httparty 耙子流产了! LoadError:无法加载此类文件— pilosa - rake aborted! LoadError: cannot load such file — pilosa rails 无法加载此类文件 -- rake (LoadError) - rails cannot load such file -- rake (LoadError) Heroku:LoadError:无法加载此类文件 — mimemagic/overlay - Heroku: LoadError: cannot load such file — mimemagic/overlay 无法加载此类文件 — rake/file_list (LoadError) - cannot load such file — rake/file_list (LoadError) LoadError:无法加载此类文件-spec / rake / spectask Fedena - LoadError: cannot load such file — spec/rake/spectask Fedena LoadError:无法加载此类文件-Heroku Ruby on Rails上的travis - LoadError: cannot load such file — travis on Heroku Ruby on Rails heroku pg:psql错误:无法加载此类文件-dl / import(LoadError) - heroku pg:psql error: cannot load such file — dl/import (LoadError) (Rails 5) LoadError: cannot load such file -- sass...当部署到 Heroku - (Rails 5) LoadError: cannot load such file -- sass ...when deploying to Heroku
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM