简体   繁体   中英

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

App uses:

  • rails 5.2.2
  • Ruby 2.5.0
  • rbenv

Whenever I run the rails s or rails c the application starts and crashes immediately with the following output:

➜  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.

Here are the things I've tried in various combinations and orders and nothing seams to work

  • bundle clean --force
  • gem uninstall --all
  • gem pristine --all
  • deleting my applications vendor/bundle directory
  • deleted my applications /tmp directory
  • adding sinatra to my gem file directly
  • gem uninstall sinatra
  • gem install sinatra
  • gem install rack-protection
  • 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.

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.

This leads me to believe the issue must be some gem dependencies screw up that's causing the problem.

This one is a total head scratcher.

Here is my 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. Installed bundler 1.17.3, ran 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.

Rails c started successfully but calling require {gem_name} led to path missing errors (below). Bundler path, gem env, gem list, etc, everything else was correct.

[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!

Of course after almost a whole day of trying to figure this out and finally posting to SO. I figure out a solution 5 minutes after the SO post goes up.

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. After doing that both rails server and rails console started working again all of a sudden.

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. Even though that it had been broken for almost 2 days. It's as if temporarily moving bootsnap down below the other gems somehow got whatever was stuck unstuck. 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?

So I'm more CONFUSED than ever but at least it working again.

  • rbenv 1.1.2
  • ruby 2.6.6
  • Rails 5.2.5

I was Having a similar problem after uninstalling my ruby 2.6.6 and installing back again, using rbenv . After running bundle rails console wouldn't work.

/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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM