LoadError: Could not load the 'listen' gem

2020-02-08 07:01发布

I've got an API mode Rails 5 app that won't let me run rake routes or rails s. The error I get is:

$ rake routes
rake aborted!
LoadError: Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile
.../config/environment.rb:5:in `<top (required)>'
LoadError: cannot load such file -- listen
.../config/environment.rb:5:in `<top (required)>'
Tasks: TOP => routes => environment
(See full trace by running task with --trace)

I've verified that listen is in the development group in my Gemfile:

group :development do
  gem 'listen', '~> 3.1.5'
  # 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

And that it's in my Gemfile.lock:

$ cat Gemfile.lock | grep 'listen'
    listen (3.1.5)
    spring-watcher-listen (2.0.0)
      listen (>= 2.7, < 4.0)
  listen (~> 3.1.5)
  spring-watcher-listen (~> 2.0.0)

I've bundle updated, and bundle installed, and verified that gem install listen works. This was working earlier this week, but I'm not having luck going back through my commits.

$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]

I don't see it in vendor/cache but I'm not sure what to make of that...

$ bundle package | grep 'listen'

Appreciate the help!

Update:

I can "fix" the problem by putting gem 'listen', '~> 3.1.5' in the global Gemfile (and removing it from :development). Then all the errors go away and everything works, but that seems wrong.

9条回答
SAY GOODBYE
2楼-- · 2020-02-08 07:25

I used this: bundle install --without development

Error:

Could not load the 'listen' gem. Add gem 'listen' to the development group of your Gemfile (LoadError)

After this, use that code:

bundle config --delete without
bundle config --delete with

Finally

bundle install
查看更多
我只想做你的唯一
3楼-- · 2020-02-08 07:25

I had same error when trying to generate mongoid database file.

but I created rails new project on ruby 2.5.1. Your ruby is 2.2. so the causality could be different in my situtation.

when I used rails new project, it was created in version 5.2, then I changed gem to 5.1.2 and problem arises. When I created with rails _5.1.6_ new in Gemfile there is generated additional pack for development.

  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

this way 'listen' showed me in gemfile automaticaly

查看更多
虎瘦雄心在
4楼-- · 2020-02-08 07:31

You might by mistake have set bundle install --without at some point, I sure did anyways.

To revert this run:

bundle config --delete without

I also ran bundle config --delete with as I manually set with option as well by mistake. Running both should get you back to default behaviour.

After having deleted the without config I could successfully run a bundle install again and afterwards my rails s, rails db:migrate etc. worked.


You can confirm if this is your issue by running bundle install and look at the second last line in the output. If it states:

Gems in the groups development and test were not installed.

It's for sure above solution should work for you.

查看更多
登录 后发表回答