LoginSignup
2
1

More than 3 years have passed since last update.

cannot load such file -- nokogiri/nokogiri (LoadError) のエラーを解決するまで。

Posted at

rails チュートリアルで学習中にrails sを実行したときに起きるエラーです。
一度解決したのですが、新しくプロジェクトを作ると同じエラー発生。一度目はひたすら記事調べていろいろした結果うまくいっただけなので、何が要因かわからずだった。なので、次すぐ解決できよう記事に志。

require': cannot load such file -- nokogiri/nokogiri (LoadError)

200行以上のエラー文の最後に、上の文章が出現。nokogiri。nokogiriをloadできないらしい。
よくわからんけど、gemfileにnokogiriを読み取れるよう設定。

gem 'nokogiri'

で、

bundle install

Traceback (most recent call last):
2: from /Users/irieryoutaira/.rbenv/versions/2.6.3/bin/bundle:23:in <main>'
1: from /Users/irieryoutaira/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems.rb:302:in
activate_bin_path'
/Users/irieryoutaira/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems.rb:283:in find_spec_for_exe': Could not find 'bundler' (2.2.6) required by your /Users/irieryoutaira/ruby/environment/toy_app/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run
bundle update --bundler.
To install the missing version, run
gem install bundler:2.2.6`

エラー。bundle 2.2.6のverをインストールするのに失敗。?はて
updateしなよって書いてある気がするから、update。

同じエラー。。
よし、ぐぐろう。

ググると、rvenvのrubyが使われてない説浮上。

which ruby 
/usr/bin/ruby

本当だ。。

rvenvのrubyが使えるようにする。
全環境で、rvenv使われていいので、

rbenv global 2.6.3

そうすると、

which ruby
/Users/irieryoutaira/.rbenv/shims/ruby

いいじゃないですか✨

と思って、
bundle update
変わらず、エラー。むむむっ。
再度、ぐぐる。
bundlerをインストールするしい。

gem install bundler

さささ、bundle install実行! そろそろ成功していいんやで。
失敗。でも、


try passing them all to `bundle update`

updateしてくださいらしい。します。

You have requested:
  listen = 3.1.5

The bundle currently has listen locked at 3.4.1.
Try running `bundle update listen`

If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`

listenがダメ??
謎謎の謎ちゃんだけど、指示どおり

bundle update listen

したら、

You have requested:
  spring = 2.1.0

The bundle currently has spring locked at 2.1.1.
Try running `bundle update spring`

If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`

次は、springがダメ。
いいでしょう。springもアップデートしますよ。

bundle update spring

すると

You have requested:
  listen = 3.1.5

The bundle currently has listen locked at 3.4.1.
Try running `bundle update listen`

If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`

デジャブ( ゚д゚)
springアップデートする前と、同じエラー。
再度、bundle update listenすると、
springのエラー。
この二つの堂々巡りがおきました。

ぐぐります。
Gemfileを
Gemfile.lockの内容より古いバージョンを指定してインストールしようとすると発生するエラーらしい。

なるほどなるほど。Gemfile.lockは消しちゃいます。bundle installで成功したら、また自動で作られるらしいから大丈V

すると、、

An error occurred while installing pg (1.1.4), and Bundler cannot
continue.
Make sure that `gem install pg -v '1.1.4' --source 'https://rubygems.org/'`
succeeds before bundling.

postgressSQL(綴りは違う気もする。)が見つかりません。だそうです。そりゃそうだよ。mysqlしか、使ったことないんだもん。なんで、前回はできんとん。。
なので、postgressSQLをインストール

brew install postgresql

そうして、

bundle install

成功!

よし!と言うことで、そろそろ、rails sしてみます。

 Webpacker configuration file not found /Users/irieryoutaira/ruby/environment/toy_app/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/irieryoutaira/ruby/environment/toy_app/config/webpacker.yml (RuntimeError)

。。。頭はげるわ。Webpacker configuration fileなる物が見つからないそう。
このwebpackerというのは、javaScriptで使うオープンソースのJavaScriptモジュールバンドラーらしい。具体的には、Webアプリケーションを構成するリソース(jsファイル、cssファイル、画像ファイル等々)を一つにまとめてくれるツールらしい。

Webpackerをインストールします。

rails webpacker:install 

でけたでけた

さあ、rails sしてみるぜ。

。。。成功!うわあ、感動した!たくさん知識を貸してくれた記事の著者さんたちありがとう!

参考にした記事は以下にあげときます。
https://techacademy.jp/magazine/19895

2
1
1

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
2
1