ruby on rails – Spring gem loaded in wrong environment

ruby on rails – Spring gem loaded in wrong environment

I faced this misunderstanding in production.

Heres how I solved it:

You can also fix this issue permanently by upspringing (removing the spring gem from) your bin/ executables:

bin/spring binstub --remove --all

Or

spring binstub --remove --all

You can now run the command below to get into rails console in production

rails c --environment=production

Also, to avoid this from occurring in subsequent occasions endeavour to make sure that the spring gem is only present in development and test groups in your Gemfile.

Moreso, when youre in production make sure you always provide the --without development test argument to the bundle install command

bundle install --without development test

and not the usual or common

bundle install

Please note: As an indication, whenever you run the command rails c or rails console and you see the output below:

Running via Spring preloader in process 26651
WARNING: Spring is running in production. To fix this make sure the spring gem is only present in development and test groups in your Gemfile and make sure you always use bundle install --without development test in production

Its an indication that the spring gem is running in your production environment, and it should be stopped or removed entirely from your bin executables.

Thats all.

I hope this helps

According the spring gem github page, it looks like rails console will load up spring:

rails console, rails generate, rails runner

These execute the rails command you already know and love. If you run
a different sub command (e.g. rails server) then spring will
automatically pass it through to the underlying rails executable
(without the speed-up).

Also, this is worrying:

You must not install Spring on your production environment. To
prevent it from being installed, provide the –without development
test argument to the bundle install command

rails console (development) would make sense, but not rails console test (or another environment). It seems buggy to me, and a reason now why I dont like the gem.

ruby on rails – Spring gem loaded in wrong environment

Spring is generally used through binstubs – did you install the binstubs? If so this is the file your rails command is running through.

#!/usr/bin/env ruby
begin
  load File.expand_path(../spring, __FILE__)
rescue LoadError => e
  raise unless e.message.include?(spring)
end
APP_PATH = File.expand_path(../config/application, __dir__)
require_relative ../config/boot
require rails/commands

As you can see it will load spring anytime you use the rails command. There is no check for the environment. If you do not want to load spring you can use DISABLE_SPRING=1 rails c test.

Leave a Reply

Your email address will not be published.