【发布时间】:2018-01-30 07:28:03
【问题描述】:
首先,尽管我们的标题几乎相同,但this post 并没有解决这个问题。
两天前,我在开发模式下运行 rails,一切都很好。今天我启动服务器,我遇到了以下错误:
/Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/nokogiri-1.8.1/lib/nokogiri.rb:33:in `require': cannot load such file -- nokogiri/nokogiri (LoadError)
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/nokogiri-1.8.1/lib/nokogiri.rb:33:in `rescue in <top (required)>'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/nokogiri-1.8.1/lib/nokogiri.rb:29:in `<top (required)>'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/loofah-2.1.1/lib/loofah.rb:3:in `require'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/loofah-2.1.1/lib/loofah.rb:3:in `<top (required)>'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/rails-html-sanitizer-1.0.3/lib/rails-html-sanitizer.rb:2:in `require'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/rails-html-sanitizer-1.0.3/lib/rails-html-sanitizer.rb:2:in `<top (required)>'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/actionview-5.1.4/lib/action_view/helpers/sanitize_helper.rb:2:in `require'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/actionview-5.1.4/lib/action_view/helpers/sanitize_helper.rb:2:in `<top (required)>'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/actionview-5.1.4/lib/action_view/helpers.rb:58:in `require'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/actionview-5.1.4/lib/action_view/helpers.rb:58:in `<module:Helpers>'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/actionview-5.1.4/lib/action_view/helpers.rb:4:in `<module:ActionView>'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/actionview-5.1.4/lib/action_view/helpers.rb:3:in `<top (required)>'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/context.rb:1:in `require'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/context.rb:1:in `<top (required)>'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/sprockets-rails-3.2.1/lib/sprockets/railtie.rb:7:in `require'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/sprockets-rails-3.2.1/lib/sprockets/railtie.rb:7:in `<top (required)>'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/sass-rails-5.0.6/lib/sass/rails/railtie.rb:3:in `require'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/sass-rails-5.0.6/lib/sass/rails/railtie.rb:3:in `<top (required)>'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/sass-rails-5.0.6/lib/sass/rails.rb:11:in `require'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/sass-rails-5.0.6/lib/sass/rails.rb:11:in `<top (required)>'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/sass-rails-5.0.6/lib/sass-rails.rb:1:in `require'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/sass-rails-5.0.6/lib/sass-rails.rb:1:in `<top (required)>'
from /Users/martin/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/runtime.rb:81:in `require'
from /Users/martin/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
from /Users/martin/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `each'
from /Users/martin/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `block in require'
from /Users/martin/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `each'
from /Users/martin/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `require'
from /Users/martin/.rvm/gems/ruby-2.4.1/gems/bundler-1.16.1/lib/bundler.rb:114:in `require'
from /Users/martin/Desktop/hotline/config/application.rb:7:in `<top (required)>'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:133:in `require'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:133:in `block in perform'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `tap'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `perform'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
from /Users/martin/Desktop/hotline/bin/rails:9:in `require'
from /Users/martin/Desktop/hotline/bin/rails:9:in `<top (required)>'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
from /Users/martin/Desktop/hotline/vendor/bundle/ruby/2.4.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
from /Users/martin/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:70:in `require'
from /Users/martin/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:70:in `require'
from /Users/martin/Desktop/hotline/bin/spring:15:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
我总结的意思是,当 rails 调用 `require 'nokogiri/nokogiri' 时,rails 找不到 gem 并且它失败了。我的第一个想法是检查我是否有宝石,所以我打电话给
>>irb
2.4.1 :001 > require 'nokogiri/nokogiri'
=> true
我的下一个想法是重新加载 nokogiri,所以我卸载并重新安装了几次,然后重新启动了我的 Mac,但无济于事。
我在网上搜索了一个咒语,我发现最接近我的解决方案的人是 Windows 存在兼容性问题。这非常无用,因为我有一台 Mac。
现在,我什至不知道我不知道什么。为什么会触发此错误?从现在到两天前,我的电脑发生了什么变化导致这个错误?我需要做什么来解决这个问题?
【问题讨论】:
-
在您的
irb中,RUBY_VERSION常量返回什么? -
RUBY_VERSION返回=> "2.4.1" -
当您安装 gem 时——通过
gem install或使用bundle——它特定于那个 Ruby 环境。您的 Rails 应用程序是为 2.4.0 捆绑的,而 Nokogiri 是为 2.4.1 安装的。将您的 Ruby 环境设置为正确的版本并再次运行bundle install,重新启动您的 Rails 服务器,您应该已经设置好了。
标签: ruby-on-rails rubygems nokogiri