0
0

More than 1 year has passed since last update.

Nokogiriのエラーで泣きそうなあなたへ

Last updated at Posted at 2022-01-19

目的

Railsアプリを作成し、Herokuへデプロイし、さぁ開発しようと思ったら以下のようなNokogiriのエラーに悩まされたので、覚えている範囲でやったことを記述していく。

環境

$ sw_vers
ProductName:    macOS
ProductVersion: 11.6
BuildVersion:   20G165

Homebrew

$ brew -v
Homebrew 3.3.11
Homebrew/homebrew-core (git revision a430b2abcc1; last commit 2022-01-19)
Homebrew/homebrew-cask (git revision b3964fe823; last commit 2022-01-19)

rbenv

$ rbenv 1.2.0
rbenv 1.2.0

rubyコマンドが置かれているディレクトリ

$ which ruby
/Users/xxx/.rbenv/shims/ruby

bundler

なお、「bundle install --path vendor/bundle」で個々のアプリケーションに分けてGemを管理しているので、インストールしたものは全てアプリケーション直下の「vendor/bundle」の中に入っております。

$ which bundle
/Users/xxx/.rbenv/shims/bundle
$ which bundler
/Users/xxx/.rbenv/shims/bundler

Rails

$ bundle exec rails -v
Rails 7.0.1

解決策

とりあえず自分が解決した方法を載せておきます。

$ bundle exec gem install nokogiri

Fetching nokogiri-1.13.1-x86_64-darwin.gem
Successfully installed nokogiri-1.13.1-x86_64-darwin
Parsing documentation for nokogiri-1.13.1-x86_64-darwin
Installing ri documentation for nokogiri-1.13.1-x86_64-darwin
Done installing documentation for nokogiri after 14 seconds
1 gem installed

その後rails sなどを起動してもエラーは出なくなりました。

エラー内容

エラー文が長すぎるので、真ん中のあたりは割愛しております。

/Users/xxx/xxx/アプリ名/vendor/bundle/ruby/3.0.0/gems/nokogiri-1.13.1-x86_64-darwin/lib/nokogiri/extension.rb:30:in `require': cannot load such file -- nokogiri/nokogiri (LoadError)
        from /Users/xxx/xxx/アプリ名/vendor/bundle/ruby/3.0.0/gems/nokogiri-1.13.1-x86_64-darwin/lib/nokogiri/extension.rb:30:in `rescue in <top (required)>'

(長いので割愛)

        from /Users/xxx/xxx/アプリ名/vendor/bundle/ruby/3.0.0/gems/railties-7.0.1/lib/rails/command.rb:48:in `invoke'
        from /Users/xxx/xxx/アプリ名/vendor/bundle/ruby/3.0.0/gems/railties-7.0.1/lib/rails/commands.rb:18:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

エラーの原因はどこにあったのか

まず参照されるべきnokogiriがどこにあるべきで、どこにないのかを見つけないといけない

エラー内容にここでLoadErrorだよと書いてので見にいく

$ cd /Users/xxx/.../アプリ名/vendor/bundle/ruby/3.0.0/gems/nokogiri-1.13.1-x86_64-darwin/lib/nokogiri/3.0

$ la
./ ../ .nokogiri.bundle.icloud*

「.nokogiri.bundle.icloud*」とはなんなんだ?と感じた。
もしかしたら「vendor/bundle」の方にnokogiriないのかもしれないと感じ
「bundle exec gem install nokogiri」コマンドを実行して、解決した。

その後、上のnokogiriの場所を見にいくと
「.nokogiri.bundle.icloud*」だとものが、「.nokogiri.bundle*」に変わっているのがわかった。

$ cd /Users/xxx/.../アプリ名/vendor/bundle/ruby/3.0.0/gems/nokogiri-1.13.1-x86_64-darwin/lib/nokogiri/3.0

$ la
./ ../ .nokogiri.bundle*

何に変わったのかまだわからないので、これから探求していきたい。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0