2

Similar question on SO, but dealing with rails 5. This instance: Rails 6.0.3 with VPS in development.

Running

RAILS_ENV=development bundle exec rails assets:precompile

on the server, or cap development deploylocally to deploy lead to the fact that listen appears to be hidden from vue.

Server:

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

local deploying:

  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

but here's the thing:

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

Commenting out the gem from the Gemfile predictably fails; I assume rails wants to know about changes and only act upon those.

Running RAILS_ENV=development bundle install returns a clue:

Gems in the groups development and test were not installed.

So how does one go about making listen gem visible?

Moving the gem call out of the development block and into the global block allows RAILS_ENV=development bundle install to run on the remote server. Now the listen gem is installed and the deployment can proceed with compilation. this is a hack, as listen is meant only for development mode; see answer below

Jerome
  • 5,583
  • 3
  • 33
  • 76
  • What does `bundle config` list for the `without` setting? Does it include `development` when it shouldn't? See https://bundler.io/guides/groups.html – pdobb Jan 14 '21 at 05:23
  • You are correct. `Set for your local app (/home/deploy/zappa/releases/20210113174140/.bundle/config): [:development, :test]` In essence saying that `Bundler.require(:default, :development)` or `bundle install --with development` should be invoked. I mistakenly assumed it was obvious if calling `RAILS_ENV=development bundle install` (I had not encountered this problem with Rails 5)? – Jerome Jan 14 '21 at 08:46
  • This appears to be the same issue, for Rails 5: https://stackoverflow.com/questions/38663706/loaderror-could-not-load-the-listen-gem-rails-5 – Colin Kelley Jan 17 '21 at 16:25
  • Discussion here: https://github.com/guard/listen/issues/530 – Colin Kelley Apr 01 '22 at 21:08

1 Answers1

1

the most direct way to overcome the issue is by adding

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

to the deploy/development.rb configuration file as per the capistrano instructions.

The default setting is:

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

which is counter-intuitive for development environment.
The error message is also misleading:

LoadError: Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile
Jerome
  • 5,583
  • 3
  • 33
  • 76