加载错误:无法加载“listen”宝石(Rails 5)

74

我有一个基于API模式的Rails 5应用程序,无法让我运行rake routesrails 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中移除它)来“修复”问题。这样所有的错误都会消失,一切都正常了,但这似乎是不正确的。


3
我曾遇到过这个问题,通过运行bundle install --with development test来解决。 - Brent
生产服务器不需要开发和测试的 gem。因此,在执行 bundle install --without development test 后,您可以通过标识环境来运行 Rails 命令。RAILS_ENV=production bundle exec rails sbundle exec rails s -e production - Oshan Wisumperuma
11个回答

0

我正在使用Docker进行工作,执行时遇到了这个错误

rails webpacker:install

这是因为这行代码在之前被执行了

ENV RAILS_ENV production
RUN chmod +x bin/rails
ENTRYPOINT ["bin/rails"]

通过将所有的Rails命令放在这个之后,解决了它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接