rails 无法加载此类文件 -- rake (LoadError)

Posted

技术标签:

【中文标题】rails 无法加载此类文件 -- rake (LoadError)【英文标题】:rails cannot load such file -- rake (LoadError) 【发布时间】:2021-04-08 06:53:01 【问题描述】:

我想在 Heroku 中推送我的第一个应用程序,但推送失败。我的 shell 中有这个错误;

Bundle completed (197.95s)
remote:        Cleaning up the bundler cache.
remote: -----> Installing node-v12.16.2-linux-x64
remote: -----> Installing yarn-v1.22.4
remote:        Detected manifest file, assuming assets were compiled locally
remote: -----> Detecting rails configuration
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_edcc391d/bin/rake:4:in `require': cannot load such file -- rake (LoadError)
remote:  !     from /tmp/build_edcc391d/bin/rake:4: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_edcc391d/bin/rake:4:in `require': cannot load such file -- rake (LoadError)
remote:     from /tmp/build_edcc391d/bin/rake:4:in `<main>'
remote:     from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/ruby.rb:1106:in `rake'
remote:     from /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/rails2.rb:85:in `has_jobs_work_task?'
bla bla bla 

所以,这是我的 Gemfile

source 'https://rubygems.org'
git_source(:github)  |repo| "https://github.com/#repo.git" 

ruby '2.7.2'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.1.0'
# Use postgresql as the database for Active Record
gem 'pg', '~> 1.1'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like javascript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
gem 'bcrypt'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
#gem 'bootsnap', '>= 1.5.1', require: true

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 4.1.0'
  # Display performance information such as SQL time and flame graphs for each request in your browser.
  # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
  gem 'rack-mini-profiler', '~> 2.0'
  gem 'listen', '~> 3.3'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 3.26'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'faker'
gem 'table_print'
gem 'bootstrap'
gem 'jquery-rails'
gem 'rake'
gem 'rack-timeout'

我想我什么都试过了。这是我尝试解决此错误的方法;

在我的 Gemfile 中添加 gem 'rake' 和 gem 'rack-timeout' 捆绑安装 git commit -m "修改的 Gemfile.lock" 添加 RAILS_SERVE_STATIC_FILES 环境。到你的服务器。 RAILS_ENV=生产包 exec rake 资产:预编译 (如果我运行 RAILS_ENV=production bundle exec rake assets:precompile,我有这个)
sh: /Users/mac/Library/Mobile: No such file or directory
sh: /Users/mac/Library/Mobile: No such file or directory
Warning: you are using an unstable release of Node.js (v15.4.0). If you encounter issues with Node.js, consider switching to an Active LTS release. More info: https://docs.npmjs.com/try-the-latest-stable-version-of-node
Everything's up-to-date. Nothing to do
git 添加公共/资产 git commit -m "供应商编译的资产" ...

但没什么,我一次又一次地遇到这个错误...... 如果有人可以帮助我,我将非常感激。

谢谢。

【问题讨论】:

【参考方案1】:

你能分享你的Gemfile.lock吗? 我遇到了同样的问题并通过将PLATFORMSx86_64-darwin-19更改为ruby来解决它。

【讨论】:

我无法将 cmets 添加到您的 Gemfile.lock,因为我没有足够的积分...您在 PLATFORMS 中看到您也只有 x86_64-darwin-17,您可以尝试添加或者用ruby替换它? 好的 @iseelotus 我只是将 x86_64-darwin-19 替换为 PLATFORMS 中的 ruby​​。现在我有很多错误。我编辑了我的上一篇文章,您可以看到错误...

以上是关于rails 无法加载此类文件 -- rake (LoadError)的主要内容,如果未能解决你的问题,请参考以下文章

Sinatra 应用程序中的“Rake 无法加载此类文件”错误

rails-rspec 错误无法加载此类文件 -- rspec/core/formatters/progress_formatter

Rails 3.2 - 无法加载初始化文件的模块

Rails 3.2 - 无法加载初始化程序文件的模块

Rails错误 - 无法加载此类文件 - aws-sdk(您可能需要安装aws-sdk gem)

为啥我无法加载此类文件?