LoadError: Could not load the 'listen' gem (Rails 6)

LoadError: Could not load the 'listen' gem (Rails 6)

关于 SO 的类似问题,但处理的是 rails 5。此实例:Rails 6.0.3,VPS 正在开发中。

运行

RAILS_ENV=development bundle exec rails assets:precompile

在服务器上,或cap development deploy本地部署导致 listen 似乎对 vue 隐藏。

服务器:

RAILS_ENV=development bundle exec rails assets:precompile
rails aborted!
LoadError: Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile

本地部署:

  01 rake aborted!
  01 LoadError: Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile
  01 /home/deploy/zappa/shared/bundle/ruby/2.6.0/gems/bootsnap-1.5.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
  01 /home/deploy/zappa/shared/bundle/ruby/2.6.0/gems/bootsnap-1.5.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
  ...
  01 Caused by:
  01 LoadError: cannot load such file -- listen

但事情是这样的:

group :development do
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '~> 3.4'
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

从 Gemfile 中注释掉 gem 预计会失败;我假设 rails 想了解变化并仅根据变化采取行动。

运行RAILS_ENV=development bundle installreturns一条线索:

Gems in the groups development and test were not installed.

那么如何才能让 listen gem 可见呢?

将 gem 调用移出 development 块并移入全局块允许远程服务器上的 RAILS_ENV=development bundle install 到 运行。现在 listen gem 已安装,部署可以继续进行编译。 这是一个 hack,因为 listen 仅适用于开发模式;请参阅下面的答案

解决这个问题最直接的方法是添加

set :bundle_without, %w{test}.join(':') 

根据 capistrano instructions 添加到 deploy/development.rb 配置文件。

默认设置为:

set :bundle_without, %w{development test}.join(':') 

这对于开发环境来说是违反直觉的。
错误信息也具有误导性:

LoadError: Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile