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

问题描述

我想在 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 add public/assets
  • git commit -m "供应商编译的资产"
  • ...

但是没什么,我一次又一次地出现这个错误...... 如果有人可以帮助我,我将不胜感激。

谢谢。

解决方法

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