LoginSignup
12
11

More than 5 years have passed since last update.

Add `gem 'listen'` to the development group of your Gemfile (LoadError)問題

Last updated at Posted at 2018-03-24

これまでのCloud9から、ローカル環境(atom)に環境移行した際に起こった問題。

移行方法は以下を参考に。
GitHubのリポジトリを自分のPCにcloneする/qiita

参考スペック

macOS High Sierra
atom 1.0.18
ruby 2.3.0p0
Rails 5.1.5
gem 2.5.1
git version 2.16.2
heroku-cli/6.14.38 (darwin-x64) node-v8.9.1

エラー内容

よっしゃ、rails立ち上げてみるかな。。と、スタートしてみたら、

$ rails s

/Users/kentaroTHEHUSKY/workspace/Proposal-market-place/vendor/bundle/gems/activesupport-5.1.5/lib/active_support/dependencie
s.rb:292:in `require': Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile (LoadError)

listen gemが読めないからdevelopment groupに追加してくださいとな?

そもそもlisten gemってなんだ?

listen
ファイルの変更を検知してそれをフックに何か処理ができるgemとのこと。
guard/listen: The Listen gem listens to file modifications and notifies you >about the changes.

ということらしい。

対応①bundle install

追加されてないとのことなので、確認。

gemfile
group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

gemファイルには記載、developmentグループに入っているので、bundle installし、無事完了。

改めてrails sするも、結果変わらず。

対応②bundle update

listen gemだけアップデートしてみる。

$bundle update listen

無事完了。
だけれども、こんなメッセージが。

The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing fo
r ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run
 `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.

bundlerの制限の話をしているみたい。
試しにやってみる。

$bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java

Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies.........
Writing lockfile to /Users/kentaroTHEHUSKY/workspace/Proposal-market-place/Gemfile.lock

rails sするも、これも結果変わらず。

対応③dependencies.rbを見てみる

冷静に今一度エラー文を見てみる。

dependencies.rb:292:in `require'

dependencies.rbの292行目は、こんな感じ。

dependencies.rb
      def require(file)
          result = false
          load_dependency(file) { result = super }
          result
      end

うーん。とりあえず怖くて触れないのでそのままに。

対応④development.rbをいじる

stackoverflowを見てみると、同じエラーが起こってる方々がまぁまぁいる模様。
この記事の部分を参考に修正を試みる。

あなたがレール5 にいて、デフォルトのconfig / environments / development.rbファイルを使用している場合、このコード行がそこにあります。

development.rb
config.file_watcher = ActiveSupport::EventedFileUpdateChecker

これは宝石を聞く必要があります。これは、私がレールを4つアップグレードしていたときに私を少し投げた

編集:それはあなたがもう聞く宝石を必要としないコード行をコメントする場合は言及して忘れてしまった

この部分をコメントアウトして再トライ。
すると、

$rails s
/Users/kentaroTHEHUSKY/workspace/Proposal-market-place/config/routes.rb:14:in `block in <top (required)>': uninitialized con
stant LetterOpenerWeb (NameError)

NameError。
listenは、letter_openerと依存関係にあるみたい。
続けて、routes.rbの14行目もコメントアウト。

routes.rb
  if Rails.env.development?
    # mount LetterOpenerWeb::Engine, at: "/letter_opener"
  end

そして、改めてrails s。

=> Booting Puma
=> Rails 5.1.5 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.3 (ruby 2.3.0-p0), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop

動いた!
が、これではletter_openerが動かないので、次回に続きます。。

2018/06/01追記

別のテストアプリでも同じ症状が現れたので、下記を参考にしたところ、問題なく動きました!
LoadError: Could not load the 'listen' gem (Rails 5)

development.rb
# 下記をコメントアウト
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker

vargant環境ならではの話らしいです。
てかこれ、対応④と同じか。。

12
11
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
12
11