5

I'm trying to add oauth2 with Google, following these instructions.

I'm receiving the following error message starting the server:

Exiting
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.

Here's the backtrace:

/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:287:in `load'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:287:in `block in load'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:287:in `load'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `<top (required)>'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in `require'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in `rescue in require'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
/Users/omonia/Dropbox/MyApp/bin/spring:13:in `<top (required)>'

The related gems installed:

gem 'google-api-client', '0.9'
gem 'omniauth'
gem 'omniauth-google_oauth2'

The following code is added to config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google_oauth2, 'my Google client id', 'my Google client secret', {client_options: {ssl: {ca_file: Rails.root.join("cacert.pem").to_s}}}
end

What is going on here? Following the error instructions doesn't change anything (Spring is of latest version 1.7.2 and running bundle exec spring binstub --all only returns "spring already present").

Fellow Stranger
  • 32,129
  • 35
  • 168
  • 232
  • Did you upgrade `Spring` ? – Arup Rakshit Jul 29 '16 at 18:02
  • Can you run first `bin/spring binstub --remove --all` and then `bundle exec spring binstub --all` ? make sure you upgrade spring befoe these all commands – Arup Rakshit Jul 29 '16 at 18:04
  • I followed your steps now, but still the same error message. I should add that this is a new app, so barely no other disturbing code at all. Second thing to add: if I remove the code in the omniauth-initializer - I don't get any error anymore. – Fellow Stranger Jul 29 '16 at 18:12
  • 2
    well what if you remove the whole spring? I think that should work. Just do `bin/spring binstub --remove --all` and remove the gem from `Gemfile` and run `bundle install` again. Ofcourse then restart the server. – Arup Rakshit Jul 29 '16 at 18:15
  • 1
    I did as you said. The error disappeared, but another error about oauth appeared instead. After googling on that error [I learned](http://codegur.com/9366579/ruby-on-rails-could-not-find-matching-strategy-for-google-oauth2) that the `omniauth-google-oauth2` gem was spelled wrong (hypen instead of underscore). After fixing the second error I tried re-adding Spring and now the original error was gone as well. Thank you a thousand times @ArupRakshit for pointing me in the right direction! – Fellow Stranger Jul 29 '16 at 18:24
  • make a PR to fix the gem error. I remember I faced the same error 1 year back. :D – Arup Rakshit Jul 29 '16 at 18:26

6 Answers6

3

Putting my comment as answer, because OP confirmed that it did help him. Follow the steps below to install the new Spring and resolve the issue:

  • run this bin/spring binstub --remove --all
  • remove the gem from Gemfile and run bundle install.
  • Now add the gem "spring", group: :development in Gemfile, run bundle install and bundle exec spring binstub --all following doc. Now all should be fine.
Community
  • 1
  • 1
Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
2

I had a similar issue after code upgrade to new rails version, and the following comment helped me resolve it:

https://github.com/rails/spring/issues/610#issuecomment-578188439

Basically, disable spring loader in bin/rails stub, then run rails s until all the code issues are found and fixed, finally, enable spring back.

Vlad
  • 3,866
  • 1
  • 24
  • 20
0

Check config/initializers/omniauth.rb file and ensure that you have following content:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google, 'Client_Id', 'Client_Secret'
end

ensure that you exactly have the google provider (not github or facebook)

Purkhalo Alex
  • 3,309
  • 29
  • 27
0

This is what worked for me -

I ran this on console - rake rails:update:bin

then I ran bundle exec spring binstub --all

I don't guarantee that this would work for all.

Thanks :)

August
  • 61
  • 6
0

First of all I am not Ruby On Rails Expert, so correct me if I am doing anything wrong with the below steps.

The steps worked for me are below,

from MacOS Terminal run the following..

bin/spring binstub --remove --all

** Remove Your Cache folder under Vender (use Finder)

bundle install.

rails assets:precompile

Nitheesh George
  • 1,357
  • 10
  • 13
0

I had a similar issue and after upgrading my ruby version from 2.6.1 to 2.7.1 and rails 5 to rails 6.

I read the discussion Here and after disable my loading spring code in bin/rails

#!/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'

TO:

#!/usr/bin/env ruby
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'

i got the error

/home/humayun/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': cannot load such file -- thwait (LoadError)

and I fix this by adding the following gems to my gem file.

gem 'cmath'
gem 'scanf'
gem 'shell'
gem 'sync'
gem 'thwait'
gem 'e2mmap'

After this, my rails s is working fine and I move bin/rails to its original code.

Humayun Naseer
  • 440
  • 7
  • 18