Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON already initialized #395

Open
cmer opened this issue Mar 9, 2017 · 4 comments
Open

JSON already initialized #395

cmer opened this issue Mar 9, 2017 · 4 comments

Comments

@cmer
Copy link

cmer commented Mar 9, 2017

Whenever I run my specs in Guard, I get a bunch of "constant already initialized" errors for json. When I run my specs directly in the terminal, I don't get this. Any idea what could be going on? I like at the Guard and Guard-Rspec code but I couldn't find anything obvious.

Thanks

0:31:43 - INFO - Run all
20:31:43 - INFO - Bundle already up-to-date
20:31:43 - INFO - Running all specs
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/version.rb:4: warning: already initialized constant JSON::VERSION
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/version.rb:4: warning: previous definition of VERSION was here
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/version.rb:5: warning: already initialized constant JSON::VERSION_ARRAY
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/version.rb:5: warning: previous definition of VERSION_ARRAY was here
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/version.rb:6: warning: already initialized constant JSON::VERSION_MAJOR
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/version.rb:6: warning: previous definition of VERSION_MAJOR was here
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/version.rb:7: warning: already initialized constant JSON::VERSION_MINOR
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/version.rb:7: warning: previous definition of VERSION_MINOR was here
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/version.rb:8: warning: already initialized constant JSON::VERSION_BUILD
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/version.rb:8: warning: previous definition of VERSION_BUILD was here
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/common.rb:100: warning: already initialized constant JSON::NaN
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/common.rb:100: warning: previous definition of NaN was here
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/common.rb:102: warning: already initialized constant JSON::Infinity
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/common.rb:102: warning: previous definition of Infinity was here
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/common.rb:104: warning: already initialized constant JSON::MinusInfinity
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/common.rb:104: warning: previous definition of MinusInfinity was here
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/common.rb:129: warning: already initialized constant JSON::UnparserError
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/common.rb:129: warning: previous definition of UnparserError was here
@cmer
Copy link
Author

cmer commented Mar 9, 2017

I found a workaround to this problem if anybody ever runs into the same issue.

I simply added gem 'json' to my Gemfile. I still have no idea what really causes the issue, however.

@ky1ejs
Copy link

ky1ejs commented Apr 14, 2017

I found that I had multiple versions of json installed. After I uninstalled them both this stopped happening:

$ gem uninstall json

Select gem to uninstall:
 1. json-1.8.6
 2. json-2.0.3
 3. All versions
> 3
Successfully uninstalled json-1.8.6
Successfully uninstalled json-2.0.3

I'm an iOS dev, quite new to Ruby, so I'm not 100% on why this error is happening. From looking around the web it seems that json was being loaded twice somehow? But I don't really get why removing it completely doesn't cause an error too. ¯_(ツ)_/¯

If I can help debug, let me know :)

@AlexWayfer
Copy link

Uninstalling non-bundled versions of json is working work-around, but they're installing again by bundle update (because newer versions of json than bundled are available).

@normanrs
Copy link

I've started avoiding ever doing a bundle update because of dependency issues. If you uninstall previous versions as described above, only install one version of the JSON gem, and add it to the Gemfile, the VERSION error goes away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants