首页 > 解决方案 > 缺少 nokogiri gemspec 时出现 Rails 控制台错误,但 nokogiri 没有 gemspec

问题描述

我尝试通过 RVM 重新安装 Ruby 2.3.6 以修复一些错误,我必须明确指定 OpenSSL 路径才能重新安装。安装 bundler 并bundle install在我的项目目录中运行后,我尝试运行rails cand bundle exec rails c,但出现此错误:

/Users/abhaskar/.rvm/gems/ruby-2.3.6@px-core/gems/bundler-1.16.1/lib/bundler/stub_specification.rb:97:in `_remote_specification': The gemspec for nokogiri-1.10.1 at /Users/abhaskar/.rvm/gems/ruby-2.3.6@px-core/specifications/nokogiri-1.10.1.gemspec was missing or broken. Try running `gem pristine nokogiri -v 1.10.1` to fix the cached spec. (Bundler::GemspecError)

然而,Nokogiri 没有 gemspec,运行建议的gem pristine命令并没有改变任何东西。我检查了 Nokogiri 是否列在我的 Gemfile 中。我的团队成员都没有面临同样的问题。如何诊断和解决此问题?

更新:bundle exec gem pristine nokogiri -v 1.10.1错误:

ERROR:  While executing gem ... (Gem::Ext::BuildError)
ERROR: Failed to build gem native extension.

current directory: /Users/abhaskar/.rvm/gems/ruby-2.3.6/gems/nokogiri-1.10.1/ext/nokogiri
/Users/abhaskar/.rvm/rubies/ruby-2.3.6/bin/ruby -r ./siteconf20190130-46592-q2jdnm.rb extconf.rb
/Users/abhaskar/.rvm/rubies/ruby-2.3.6/lib/ruby/site_ruby/2.3.0/bundler/spec_set.rb:91:in `block in materialize': Could not find nokogiri-1.10.1 in any of the sources (Bundler::GemNotFound)

标签: ruby-on-railsrubynokogiribundler

解决方案


这是我的强烈建议:保释 rvm 并转移到 docker。你每次都得到一个干净的构建。不用担心在不同项目之间混合系统库。等等

了解 docker 有一点开销,但是一旦你这样做了,你就可以自由地运行任何版本的 postgres/mysql/rails/ruby/whatever 并随意混合和匹配。


推荐阅读