LoadError: Could not load the 'listen' gem (Rails 5)

前端 未结 10 474
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 05:36

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!
Lo         


        
相关标签:
10条回答
  • 2020-12-14 06:02

    I'm posting this as an answer, but I don't like it.

    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.

    0 讨论(0)
  • 2020-12-14 06:03

    I had the same problem, i fix it by running

    rails c -e production
    
    0 讨论(0)
  • 2020-12-14 06:11

    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
    
    0 讨论(0)
  • 2020-12-14 06:12

    If you are on rails 5 and you are using the default config/environments/development.rb file it will have this line of code in there.

    config.file_watcher = ActiveSupport::EventedFileUpdateChecker
    

    This requires the gem listen. This threw me for a bit as I was doing a rails 4 upgrades to a rails 5

    edit: Forgot to mention that if you comment that line of code out it will not need the listen gem anymore.

    0 讨论(0)
  • 2020-12-14 06:17

    I had the same issue. Thanks to @newdark answer I figured out the correct solution. Basically I wanted to deploy rails in production mode. But obviously forgot to set environment variable RAILS_ENV=production before running server.

    So to recap, dependencies for production mode were installed while rails tried to start in development mode due to forgetting to set RAILS_ENV=production. If I went on to add gem listen to the production dependencies, I'd be running in development mode without being able to notice.

    For me the solution was to do export RAILS_ENV=production before executing any rails commands and keep dependencies intact. Hope I managed to explain.

    0 讨论(0)
  • 2020-12-14 06:18

    I'm having the same problem by running rails c.

    By reading this other Stack Overflow post I did realize that it is normal that both bundle exec rake command or rails console are running in a default production environment.

    I figured I will solve the issue either by:

    1. adding export RAILS_ENV=production in ~/.bash_profile
    2. explicitly writing the environment in which I want the command to execute like bundle exec rake a_rake:task RAILS_ENV=production rails console --env=production etc...
    0 讨论(0)
提交回复
热议问题