简体   繁体   English

Rails 服务器和 Rails 控制台崩溃:要求':无法加载此类文件 -- 机架/保护 (LoadError)

[英]Rails server and Rails console crash with: require': cannot load such file -- rack/protection (LoadError)

Not sure exactly why or how this started happening but all of a sudden my application which was running fine on my local environment is no longer working.不确定为什么或如何开始发生这种情况,但突然间我在本地环境中运行良好的应用程序不再工作。

My local dev environment is: MacOS Sierra 10.12.5我的本地开发环境是:MacOS Sierra 10.12.5

App uses:应用程序用途:

  • rails 5.2.2导轨 5.2.2
  • Ruby 2.5.0红宝石 2.5.0
  • rbenv环境

Whenever I run the rails s or rails c the application starts and crashes immediately with the following output:每当我运行 rails s 或 rails c 时,应用程序都会立即启动并崩溃,并显示以下输出:

➜  pwf-site git:(master) ✗ rails c
Traceback (most recent call last):
    67: from bin/rails:4:in `<main>'
    66: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
    65: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
    64: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
    63: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
    62: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
    61: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
    60: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
    59: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
    58: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/commands.rb:18:in `<main>'
    57: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/command.rb:46:in `invoke'
    56: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/command/base.rb:65:in `perform'
    55: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
    54: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
    53: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
    52: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/commands/console/console_command.rb:95:in `perform'
    51: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/command/actions.rb:18:in `require_application_and_environment!'
    50: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:337:in `require_environment!'
    49: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
    48: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
    47: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
    46: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
    45: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
    44: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
    43: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
    42: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
    41: from /Users/herbyraynaud/code/personal/pwf-site/config/environment.rb:5:in `<main>'
    40: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:361:in `initialize!'
    39: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:60:in `run_initializers'
    38: from /Users/herbyraynaud/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:205:in `tsort_each'
    37: from /Users/herbyraynaud/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:226:in `tsort_each'
    36: from /Users/herbyraynaud/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:347:in `each_strongly_connected_component'
    35: from /Users/herbyraynaud/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:347:in `call'
    34: from /Users/herbyraynaud/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:347:in `each'
    33: from /Users/herbyraynaud/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:349:in `block in each_strongly_connected_component'
    32: from /Users/herbyraynaud/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:431:in `each_strongly_connected_component_from'
    31: from /Users/herbyraynaud/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    30: from /Users/herbyraynaud/.rbenv/versions/2.5.0/lib/ruby/2.5.0/tsort.rb:228:in `block in tsort_each'
    29: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'
    28: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `run'
    27: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `instance_exec'
    26: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application/finisher.rb:130:in `block in <module:Finisher>'
    25: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:10:in `execute'
    24: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/file_update_checker.rb:83:in `execute'
    23: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:30:in `block in updater'
    22: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:20:in `reload!'
    21: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:41:in `load_paths'
    20: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:41:in `each'
    19: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:41:in `block in load_paths'
    18: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
    17: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
    16: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `block in load'
    15: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
    14: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
    13: from /Users/herbyraynaud/code/personal/pwf-site/config/routes.rb:1:in `<main>'
    12: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
    11: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
    10: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
     9: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
     8: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
     7: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
     6: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
     5: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
     4: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.2.5/lib/sidekiq/web.rb:13:in `<main>'
     3: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
     2: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
     1: from /Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
/Users/herbyraynaud/code/personal/pwf-site/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require': cannot load such file -- rack/protection (LoadError)

the rack-protection gem is part of Sinatra so i tried to add sinatra to the Gemfile as well as doing a normal gem install but it looks like that was a red-herring.机架保护gem 是Sinatra 的一部分,所以我尝试将sinatra添加到 Gemfile 以及进行正常的 gem 安装,但看起来这是一个红鲱鱼。

Here are the things I've tried in various combinations and orders and nothing seams to work以下是我以各种组合和顺序尝试过的东西,没有任何接缝可以工作

  • bundle clean --force捆绑清洁 --force
  • gem uninstall --all宝石卸载 --all
  • gem pristine --all宝石原始 - 全部
  • deleting my applications vendor/bundle directory删除我的应用程序供应商/捆绑目录
  • deleted my applications /tmp directory删除了我的应用程序 /tmp 目录
  • adding sinatra to my gem file directly直接将 sinatra 添加到我的 gem 文件中
  • gem uninstall sinatra宝石卸载 sinatra
  • gem install sinatra宝石安装 sinatra
  • gem install rack-protection gem 安装机架保护
  • gem update --system宝石更新--系统

There are some similar issue suggesting that the problem is with the bootsnap gem but they proved to be red herring removing the gem and disabling bootsnap in the boot.rb file didn't resolve the problem.有一些类似的问题表明问题出在 bootsnap gem 上,但事实证明是红鲱鱼移除了 gem 并且在 boot.rb 文件中禁用 bootsnap 并没有解决问题。

Finally, I'm able to create a new rails app other than fixing an sqlite3 version issue I'm able to run the server and console with no issues.最后,除了修复 sqlite3 版本问题之外,我还可以创建一个新的 Rails 应用程序,我可以毫无问题地运行服务器和控制台。

This leads me to believe the issue must be some gem dependencies screw up that's causing the problem.这让我相信问题一定是导致问题的一些 gem 依赖关系搞砸了。

This one is a total head scratcher.这是一个完全令人头疼的问题。

Here is my Gemfile这是我的 Gemfile

source 'https://rubygems.org'
ruby "2.5.0"

gem 'rails', '5.2.2'
gem 'bootsnap'
gem 'devise'
gem "simple_form"
gem 'simple_enum', git: 'git://github.com/lwe/simple_enum.git'
gem 'kaminari'
gem 'activerecord-import'
gem 'font-awesome-sass', '~> 5.2.0'
gem 'pg'
gem 'puma', '~> 3.7'
gem 'activeadmin'
gem 'activeadmin_blaze_theme'
gem 'inherited_resources'
gem 'stripe'
gem "aws-sdk-s3",  require: false
gem "image_processing", "~> 1.2"
gem "prawn"#, :git => "git://github.com/prawnpdf/prawn.git"
gem 'prawn-table' #, '~> 0.1.0'
gem "bootstrap", ">= 4.3.1"
gem 'jquery-rails'
gem "chosen-rails"
gem 'rails-observers'
gem 'combine_pdf'
gem 'figaro'
gem 'exception_handler'
gem "chartkick"
gem 'activeadmin_medium_editor', git: "git://github.com/hraynaud/activeadmin_medium_editor.git"
gem 'sidekiq'

group :development, :test do
  gem "better_errors"
  gem "hirb"
  gem 'rspec'
  gem "rspec-rails"
  gem 'factory_bot' 
  gem "factory_bot_rails"
  gem "faker"
  gem "populator"
  gem "pry"
  gem "pry-nav"
  gem "fakeweb", git: "https://github.com/chrisk/fakeweb.git"
  gem "letter_opener"
end

group :test do
  gem 'capybara'
  gem "guard-rspec"
  gem "rspec-activemodel-mocks"
  gem "database_cleaner"
  gem "launchy"
  gem 'simplecov', :require => false
  gem 'selenium-webdriver'
  gem 'chromedriver-helper'
end

I had a similar issue that this solution resolved.我有一个类似的问题,这个解决方案解决了。

Upgraded ruby version to 2.5.1 from 2.3.4 using rbenv.使用 rbenv 将 ruby​​ 版本从 2.3.4 升级到 2.5.1。 Installed bundler 1.17.3, ran bundle install .安装 bundler 1.17.3,运行bundle install Everything installed correctly but due to bootsnap cache my rails console kept using an older set of gems and would not load newly installed ones.一切都安装正确,但由于 bootsnap 缓存,我的 rails 控制台一直使用旧的 gems 集,不会加载新安装的 gems。

Rails c started successfully but calling require {gem_name} led to path missing errors (below). Rails c 成功启动,但调用require {gem_name}导致路径丢失错误(如下)。 Bundler path, gem env, gem list, etc, everything else was correct. Bundler 路径、gem env、gem 列表等,其他一切都是正确的。

[5] pry(main)> require 'simple_enum'
LoadError: cannot load such file -- simple_enum
from /Users/max/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'

Finally cleared the tmp/cache folder, bundle updated bootsnap, and everything worked!最后清除 tmp/cache 文件夹,捆绑更新的引导程序,一切正常!

Of course after almost a whole day of trying to figure this out and finally posting to SO.当然,经过几乎一整天的尝试并最终发布到 SO。 I figure out a solution 5 minutes after the SO post goes up.我在 SO 帖子发布 5 分钟后找到了解决方案。

The one thing that I didn't try was to move the line:我没有尝试的一件事是移动线:

gem bootsnap

to later in the Gemfile below all the default gems but before the development and test group.稍后在 Gemfile 下所有默认 gems 但在开发和测试组之前。 After doing that both rails server and rails console started working again all of a sudden.这样做之后,rails server 和 rails console 突然又开始工作了。

What's weird is I wanted to verify that this was indeed the issue so I undid the change deleted the bootsnap cache in tmp/cache , deleted my vendor/bundle directory and re-performed bundle install and it's worked just fine.奇怪的是,我想验证这确实是问题所在,所以我取消了更改,删除了tmp/cache 中的 bootsnap缓存,删除了我的 vendor/bundle 目录并重新执行了bundle install并且它工作得很好。 Even though that it had been broken for almost 2 days.即使它已经坏了将近2天。 It's as if temporarily moving bootsnap down below the other gems somehow got whatever was stuck unstuck.就好像暂时将 bootsnap 向下移动到其他 gem 下方以某种方式使卡住的东西脱开一样。 What's odd is that not even removing bootsnap from my application completely was able to get it working again but just temporarily moving it to near the bottom of the Gemfile did the trick?奇怪的是,即使从我的应用程序中完全删除 bootsnap 也不能让它再次工作,但只是暂时将它移动到 Gemfile 的底部附近就成功了?

So I'm more CONFUSED than ever but at least it working again.所以我比以往任何时候都更加困惑,但至少它再次起作用了。

  • rbenv 1.1.2 rbenv 1.1.2
  • ruby 2.6.6红宝石 2.6.6
  • Rails 5.2.5导轨 5.2.5

I was Having a similar problem after uninstalling my ruby 2.6.6 and installing back again, using rbenv .在卸载我的ruby 2.6.6并使用rbenv重新安装后,我遇到了类似的问题。 After running bundle rails console wouldn't work.运行bundle rails console后不起作用。

/Users/jmschp/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': cannot load such file -- /Users/jmschp/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/e2mmap-0.1.0/lib/e2mmap.rb (LoadError)

What solved the problem for me was running rails tmp:clear .为我解决问题的是运行rails tmp:clear

暂无
暂无

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

相关问题 Rails服务器正常工作,Rails控制台无效。 `require&#39;:无法加载此类文件-捆绑程序/安装程序(LoadError)- - Rails server works, Rails console does not. `require': cannot load such file — bundler/setup (LoadError) - Rails 控制台:在“require”中:无法加载此类文件 — readline (LoadError) - Rails console: in `require': cannot load such file — readline (LoadError) Docker编译失败并显示“ require”:无法加载此类文件-机架/处理器/导轨(LoadError) - Docker compose up fails with `require': cannot load such file — rack/handler/rails (LoadError) rails服务器抛出`require&#39;:无法加载这样的文件 - bigdecimal / util(LoadError) - rails server throws `require': cannot load such file — bigdecimal/util (LoadError) `require&#39;:无法加载此类文件-rails / all(LoadError) - `require': cannot load such file — rails/all (LoadError) Rails Rspec `require': 无法加载此类文件 -- rails_helper (LoadError) - Rails Rspec `require': cannot load such file -- rails_helper (LoadError) require': 无法加载此类文件 -- mysql2/mysql2 (LoadError) rails 4 - require': cannot load such file -- mysql2/mysql2 (LoadError) rails 4 Ruby on Rails:错误“require”:无法加载此类文件——bundler/setup (LoadError) - Ruby on Rails: Error `require': cannot load such file -- bundler/setup (LoadError) &#39;require&#39;: 无法加载此类文件 -- 运行 `rails server` 时出现 &#39;nokogiri\\nokogiri&#39; (LoadError) - 'require': cannot load such file -- 'nokogiri\nokogiri' (LoadError) when running `rails server` 无法运行rails服务器:`require&#39;:无法加载此类文件--net / ssh(LoadError) - Unable to run rails server: `require': cannot load such file — net/ssh (LoadError)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM