ruby-on-rails - 加载错误: Could not load the 'listen' gem (Rails 5)

标签 ruby-on-rails ruby-on-rails-5 listen

我有一个 API 模式 Rails 5 应用程序,它不允许我运行 rake pathsrails 。我得到的错误是:

$ 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)

我已验证 listen 位于我的 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

它在我的 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)

我已经更新了 bundle ,安装了 bundle ,并验证了 gem install Listen 是否有效。这是本周早些时候的工作,但我没有运气通过我的 promise 。

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

我在 vendor/cache 中没有看到它,但我不知道该怎么做......

$ bundle package | grep 'listen'

感谢您的帮助!

更新:

我可以通过将 gem 'listen', '~> 3.1.5' 放入全局 Gemfile 中(并将其从 :development 中删除)来“修复”该问题。然后所有错误都会消失,一切正常,但这似乎是错误的。

最佳答案

如果您使用的是 Rails 5 并且使用默认的 config/environments/development.rb 文件,它将包含这行代码。

config.file_watcher = ActiveSupport::EventedFileUpdateChecker

这需要 gem 监听。当我将 Rails 4 升级到 Rails 5 时,这让我有点困惑

编辑: 忘记提及,如果您注释掉该行代码,它将不再需要监听 gem。

关于ruby-on-rails - 加载错误: Could not load the 'listen' gem (Rails 5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38663706/

相关文章:

mongodb - Node.js 监听 MongoDB 变化

sql - 当事件范围超过一个月时按月汇总事件成本(在 rails 3 中)

ruby-on-rails - Postgresql 无法连接到服务器?

css - 以简单形式和载波自定义图像上传字段

ruby-on-rails - NameError : undefined local variable or method `app' for - Rails 5. 1.6升级

ruby-on-rails - Rails 5.2 简单形式 Lambda 函数

c++ - 如何在同一端口上运行套接字和 websocket 服务器?

c++ - 非本地 IP 的套接字监听器不起作用

ruby-on-rails - Active Record 序列化 attr 丢失字符串编码(可能是 YAML 问题),解决方法?

javascript - FB 分享按钮在页面加载时消失