Ruby on rails LoadError:无法加载';听一听';宝石(轨道5)
我有一个API模式的Rails 5应用程序,它不允许我运行Ruby on rails LoadError:无法加载';听一听';宝石(轨道5),ruby-on-rails,ruby-on-rails-5,listen,Ruby On Rails,Ruby On Rails 5,Listen,我有一个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)>' Load
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)
它在我的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)
我在供应商/cache
中看不到它,但我不确定该怎么做
$ bundle package | grep 'listen'
谢谢你的帮助
更新:
我可以通过将
gem'listen'、'~>3.1.5'
放入全局gem文件(并将其从:development
中删除)来“修复”问题。然后所有的错误都消失了,一切正常,但这似乎是错误的。我将此作为答案发布,但我不喜欢它。
我可以通过将
gem'listen'、'~>3.1.5'
放入全局gem文件(并将其从:development
中删除)来“修复”问题。然后所有的错误都消失了,一切正常,但这似乎是错误的。您可能错误地设置了bundle install——在某个时候没有,无论如何,我确实这样做了
要恢复此运行,请执行以下操作:
bundle配置--删除而不删除
我还运行了bundle config--delete with
,因为我手动设置了with
选项。运行这两种方法应该会使您恢复默认行为
在删除了没有配置的后,我可以再次成功运行捆绑安装,然后我的rails s
,rails db:migrate
等工作正常
您可以通过运行bundle install
并查看输出中的最后一行来确认这是否是您的问题。如果声明:
未安装开发和测试组中的Gems。
以上解决方案肯定适合您。如果您在rails 5上,并且使用默认的config/environments/development.rb文件,那么其中将包含这一行代码
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
这需要宝石听。当我在做rails 4升级到rails 5时,这让我有点吃惊
编辑:
忘了提一下,如果你把那行代码注释掉,它就不再需要listen gem了。我也有同样的问题。多亏了@newdark answer,我找到了正确的解决方案。基本上我想在生产模式下部署rails。但显然忘记了在运行服务器之前设置环境变量RAILS\u ENV=production
综上所述,由于忘记设置rails\u ENV=production
,rails试图在development
模式下启动时,安装了production
模式的依赖项。如果我继续将gemlisten
添加到production
依赖项中,我将在开发模式下运行,而不会注意到
对我来说,解决方案是在执行任何RAILS命令之前执行导出RAILS\u ENV=production
,并保持依赖关系完好无损。希望我能解释清楚。通过运行rails c
我也遇到了同样的问题
通过阅读另一个堆栈溢出,我确实意识到,bundle exec rake
命令或rails console
都在默认的生产环境中运行是正常的
我想我可以通过以下方式解决这个问题:
在~/.bash\u配置文件中添加export RAILS\u ENV=production
显式编写希望命令在其中执行的环境,如bundle exec rake a\u rake:task RAILS\u ENV=production
RAILS控制台--ENV=production
等
我使用的是:bundle安装——无需开发
错误:
无法加载“侦听”宝石。将gem'listen'
添加到Gemfile的开发组(LoadError)
在此之后,使用该代码:
bundle config --delete without
bundle config --delete with
最后
bundle install
我也有同样的问题,我通过运行
rails c -e production
今天从Rails 5.1.5升级到5.2.0后,我遇到了类似的问题。第一次运行服务器时出现以下“缺少资产”问题:
ActionView::Template::Error (The asset "asterisk_orange.png" is not present in the asset pipeline.)
尝试预编译资产时显示“gem侦听错误”:
$ bundle exec rake assets:precompile
rake aborted!
LoadError: Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile
我的解决方案是显式设置生产环境:
$ RAILS_ENV=production bundle exec rake assets:precompile
这将预编译没有问题的资产,并且“缺少资产”问题已得到修复。我在尝试生成mongoid数据库文件时遇到了相同的错误
但是我在ruby 2.5.1上创建了rails新项目
。您的ruby
是2.2
。所以因果关系在我的情况下可能不同
当我使用railsnewproject
时,它是在版本5.2中创建的,然后我将gem更改为5.1.2,问题就出现了。当我在Gemfile中使用rails\u5.1.6\unew
创建时,会生成额外的开发包
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# 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
小组:开发
#在异常页面上或通过使用代码中的任意位置访问IRB控制台。
gem“web控制台”,“>=3.3.0”
gem'listen','>=3.0.5','<3.2'
#Spring通过让应用程序在后台运行来加速开发。阅读更多:https://github.com/rails/spring
宝石“春天”
gem‘SpringWatcherListen’,“~>2.0.0”
结束
通过这种方式“倾听”在gemfile Automatically中向我展示了这一点经过大量的重建尝试后,我找到了一个简单的修复方法
bundle config --delete without
bundle config --delete with
bundle install
如果您在正确设置环境之前意外构建了gemset,那么这可能有助于解决问题。现在有相同的问题,对此有什么更新吗?@PetrosKyriakou遗憾的是没有。希望发布的解决方案同时对您有效。嗯,是的,但我并不比您更喜欢此解决方案。。。无论如何谢谢你!嗨,我想知道是否有可能完全禁用listen gem?特别是在生产中?我今天也犯了同样的错误,我检查了我的怀疑,结果证明我是对的。我会发布一个可能的答案。谢谢。我需要把这句话注释掉。这是一种无声的依赖,因为它不会在bundler中显示为依赖
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# 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
bundle config --delete without
bundle config --delete with
bundle install