【发布时间】:2016-12-04 11:01:48
【问题描述】:
我有一个 API 模式的 Rails 5 应用程序,它不允许我运行 rake routes 或 rails s。我得到的错误是:
$ 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)
我已经更新了捆绑包,安装了捆绑包,并验证了 gem install listen 是否有效。这在本周早些时候工作,但我没有运气回过头来完成我的提交。
$ 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 中删除)来“解决”问题。然后所有错误都消失了,一切正常,但这似乎是错误的。
【问题讨论】:
-
我遇到了这个问题并通过运行
bundle install --with development test解决了它。 -
生产服务器不需要开发和测试 gem。所以在
bundle install --without development test之后,您可以通过识别环境来运行rails 命令。RAILS_ENV=production bundle exec rails s或bundle exec rails s -e production
标签: ruby-on-rails ruby-on-rails-5 listen