我有一个 API 模式 Rails 5 应用程序,它不允许我运行 rake paths
或 rails
。我得到的错误是:
$ 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/