如何修复:Bundler 找不到 gem "nokogiri" 的兼容版本

how to fix : Bundler could not find compatible versions for gem "nokogiri"

我是 ruby 的新手,我正在尝试 运行 我的第一个应用程序,但是当我启动服务器时出现此错误:

Bundler could not find compatible versions for gem "nokogiri":   In Gemfile:
    capybara (>= 2.15) x86-mingw32 was resolved to 3.15.1, which depends on
      nokogiri (~> 1.8)
Could not find gem 'nokogiri (~> 1.8)', which is required by gem 'capybara (>= 2.15)', in any of the sources.

我尝试了很多解决方案并且 none 成功了,例如我尝试了 bundle install bundle update bundle exec 我有 ruby 版本 2.3.3, rails 版本 5.1.7 当我从应用程序文件夹外部 运行 rails -v 时,但从内部我得到与上面相同的错误

这里是 gem 文件:

source 'https://rubygems.org'
git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.7'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

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]
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]```


  [1]: https://i.stack.imgur.com/6sNnN.png

我 运行 bundle pristine 我得到了这个:

--- ERROR REPORT TEMPLATE -------------------------------------------------------
# Error Report

## Questions

Please fill out answers to these questions, it'll help us figure out
why things are going wrong.

- **What did you do?**

  I ran the command `C:/RailsInstaller/Ruby2.3.3/bin/bundle pristine`

- **What did you expect to happen?**

  I expected Bundler to...

- **What happened instead?**

  Instead, what happened was...

- **Have you tried any solutions posted on similar issues in our issue tracker, stack overflow, or google?**

  I tried...

- **Have you read our issues document, https://github.com/rubygems/rubygems/blob/master/bundler/doc/contributing/ISSUES.md?**

  ...

## Backtrace


NoMethodError: undefined method `specs' for nil:NilClass
  C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/bundler-2.2.0.rc.1/lib/bundler/cli/common.rb:72:in `ensure_all_gems_in_lockfile!'
  C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/bundler-2.2.0.rc.1/lib/bundler/cli/pristine.rb:10:in `run'
  C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/bundler-2.2.0.rc.1/lib/bundler/cli.rb:705:in `pristine'
  C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/bundler-2.2.0.rc.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
  C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/bundler-2.2.0.rc.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
  C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/bundler-2.2.0.rc.1/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
  C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/bundler-2.2.0.rc.1/lib/bundler/cli.rb:30:in `dispatch'
  C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/bundler-2.2.0.rc.1/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
  C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/bundler-2.2.0.rc.1/lib/bundler/cli.rb:24:in `start'
  C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/bundler-2.2.0.rc.1/exe/bundle:49:in `block in <top (required)>'
  C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/bundler-2.2.0.rc.1/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
  C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/bundler-2.2.0.rc.1/exe/bundle:37:in `<top (required)>'
  C:/RailsInstaller/Ruby2.3.3/bin/bundle:23:in `load'
  C:/RailsInstaller/Ruby2.3.3/bin/bundle:23:in `<main>'


## Environment


Bundler       2.2.0.rc.1
  Platforms   ruby, x86-mingw32
Ruby          2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
  Full Path   C:/RailsInstaller/Ruby2.3.3/bin/ruby.exe
  Config Dir  C:/ProgramData
RubyGems      3.1.4
  Gem Home    C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0
  Gem Path    C:/Users/Moham/.gem/ruby/2.3.0;C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0
  User Home   C:/Users/Moham
  User Path   C:/Users/Moham/.gem/ruby/2.3.0
  Bin Dir     C:/RailsInstaller/Ruby2.3.3/bin
Tools
  Git         2.28.0.windows.1
  RVM         not installed
  rbenv       not installed
  chruby      not installed


## Bundler Build Metadata


Built At          2020-07-02
Git SHA           d15da3db73
Released Version  true


## Gemfile

### Gemfile

ruby
source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

gem 'nokogiri', '~> 1.8'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.7'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

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]
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]


### Gemfile.lock


<No D:/web developing/AAL/Ruby on rails/module 3/create app/my_first_app/Gemfile.lock found>


--- TEMPLATE END ----------------------------------------------------------------

Unfortunately, an unexpected error occurred, and Bundler cannot continue.

First, try this link to see if there are any existing issue reports for this error:
https://github.com/rubygems/rubygems/search?q=undefined+method+%60specs%27+for+nil+NilClass&type=Issues

If there aren't any reports for this error yet, please create copy and paste the report template above into a new issue. Don't forget to anonymize any private data! The new issue form is located at:
https://github.com/rubygems/rubygems/issues/new?labels=Bundler```

请 post 您的 Gemfile.lock 确认 - 但这看起来水豚版本被锁定为 '>=2.15' 并且 [=16] 中不存在与之兼容的 nokogiri 版本=].

一个快速解决方法是在您的 Gemfile 中将 nokogiri 显式设置为 'nokogiri', '~> 1.8' 并查看问题是否仍然存在。您可能想要升级您的水豚版本以匹配与其他需要它的 gem 兼容的 nokogiri 版本

最后按照以下步骤解决了问题:

  1. 卸载 rails 安装程序并手动删除文件夹。
  2. 设置 ruby 安装程序。
  3. 运行 gem install rails
  4. 安装纱线。
  5. 重启电脑
  6. 运行 rails webpacker:install.