4

I have created a new rails application folder, which worked smoothly. Once within such folder, running any kind of rails command like rails s will prompt me:

You've tried to invoke Spring when it's already loaded (i.e. the Spring constant is defined).

This is probably because you generated binstubs with Spring 1.0, and you now have a Spring version > 1.0 on your system. To solve this, upgrade your bundle to the latest Spring version and then run `bundle exec spring binstub --all` to regenerate your binstubs. This is a one-time step necessary to upgrade from 1.0 to 1.1.

I currently have

spring -v
Spring version 2.1.0

I've tried the following, getting the same results. I also tried uninstalling spring and reinstalling.

 bundle exec spring binstub --all
* bin/rake: Spring already present
* bin/rails: Spring already present
Gotey
  • 449
  • 4
  • 15
  • 41
  • 1
    Have you tried running `bundle exec spring binstub --all` ? – Mark Jan 03 '20 at 13:43
  • Yes, it doesn't seem to do any changes. – Gotey Jan 03 '20 at 13:45
  • 1
    Some of the steps from https://stackoverflow.com/questions/38664754/spring-and-middleware-conflict might help – Mark Jan 03 '20 at 13:59
  • 4
    I've tried the indications in that post and kept not working. Somehow running `gem pristine --all` solves the issue, but not sure why – Gotey Jan 03 '20 at 14:05
  • `gem pristine --all` left me with `ERROR: While executing gem ... (Errno::EPERM) Operation not permitted @ apply2files - /Users/xxxxxxxxxx/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionmailbox-6.1.4/CHANGELOG.md` – J.R. Bob Dobbs Aug 07 '21 at 01:50

3 Answers3

9

Posting this as an answer after trying every other related solutions to finally find this hidden in a comment. Hope it helps someone in the future.

As for the why, the only reason I see on my side is upgrading from ubuntu (pop os) 20.04 to 20.10. Didn't do anything else between my two coding sessions.

I've tried the indications in that post and kept not working. Somehow running gem pristine --all solves the issue, but not sure why – Gotey Jan 3 at 14:05

  • 1
    This only left me with an error. A new error, but an error nonetheless: `ERROR: While executing gem ... (Errno::EPERM) Operation not permitted @ apply2files - /Users/xxxxxxx/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionmailbox-6.1.4/CHANGELOG.md` – J.R. Bob Dobbs Aug 07 '21 at 01:51
  • This worked for me, this command clean all gems for the current ruby version. And by the documentation, with "bundle pristine" the same occur only by gem on lockfile. https://bundler.io/man/bundle-pristine.1.html#:~:text=Meanwhile%2C%20gem%20pristine%20%2D%2Dall,and%20instead%20run%20bundle%20pristine%20. – Leandro Arruda Dec 13 '21 at 00:06
1

It may happen when you've require something in your code which is not installed.

For instance, I've encountered this issue when I was imported sentry-ruby without installing actual gem. Check your dependencies and imports.

Vova Rozhkov
  • 1,582
  • 2
  • 19
  • 27
0

For me, I removed the spring and spring-watcher-listen gems from the Gemfile and then uninstalled these 2 gems via the bundle exec gem uninstall gemname command.

I then discovered a new error when trying to run rails s which was about MySQL. Finally after fixing those errors I was able to do a successful rails s. I then added back the 2 gems, ran bundle and had no errors afterwards.

PierceF
  • 53
  • 6