我有一个基于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)
我已经更新了bundle,并且安装了bundle,还验证gem install listen
可用。这个在本周早些时候是可以工作的,但是我在回顾我的提交记录时没有运气。
$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
我没有在vendor/cache
目录中看到它,但我不确定这意味着什么...
$ bundle package | grep 'listen'
感谢帮助!
更新:
我可以通过在全局Gemfile中加入gem 'listen', '~> 3.1.5'
(并从:development
中移除它)来“修复”问题。这样所有的错误都会消失,一切都正常了,但这似乎是不正确的。
bundle install --with development test
来解决。 - Brentbundle install --without development test
后,您可以通过标识环境来运行 Rails 命令。RAILS_ENV=production bundle exec rails s
或bundle exec rails s -e production
。 - Oshan Wisumperuma