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
Already initialized constant #37
Comments
Hi @cwsaylor, what version were you using and what were you doing when you get this error? |
Latest master right now, though I've been seeing this error for all versions since I started using the shippo gem a couple months ago. I'm also using Ruby 2.3. The error happens any time I run a rake command, tests, server, pretty much everything. |
Thank you @cwsaylor, I will look into it on Monday. Will get back to you soon! |
@cwsaylor did you post all the warning message? I don't think it has to do with the |
@cwsaylor, please let me know if you are able to solve the issue with my last comment when you have a chance. Thanks! |
It's still occurring.
@wenwei1030 What does your setup look like? |
@cwsaylor Can you try that in Rails 4? |
@cwsaylor We are working on that now. |
I think I found the issue. Fire up a console and check out the loaded files.
You can see some of the files are loaded twice from different paths. rbenv uses symlinks in /usr/local/opt to point to point to files in /usr/local/Cellar. You are correct in that it isn't specifically a require_relative issue. I think it's related to mixing require and require_relative. One is resolving symlinked paths and the other isn't, so the files appear different and are loaded twice.
|
@cwsaylor That's interesting. I can't reproduce the problem. I created a new rails 5 app and installed the latest shippo gem. I went to the console and run the command you gave. Here is what I got:
Do I need to do anything else? |
It's because you're using RVM. RVM doesn't use symlinks in its gem path, so when the different require statements resolve the paths to the files, it always resolves to the same path, so it doesn't require twice. |
@cwsaylor I see. Can you try to use your local gem with the changes in your pull request to see if that works? |
Edited: I realized this wasn't a direct comparison so I setup a symlink to my local code folder with my changes. When I switch to my branch which has the require_relative statements changed to requires, the files which define the constants are no longer loaded twice, so the error goes away. However, there are still two files loaded twice.
|
I'm getting a bunch of warnings related to already initialized constant. I believe this to be caused by using require_relative.
/usr/local/opt/rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/shippo-ruby-client-b66c1bef50e8/lib/shippo/api/api_object.rb:63: warning: already initialized constant Shippo::API::ApiObject::PREFIX /usr/local/Cellar/rbenv/1.1.0/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/shippo-ruby-client-b66c1bef50e8/lib/shippo/api/api_object.rb:63: warning: previous definition of PREFIX was here /usr/local/opt/rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/shippo-ruby-client-b66c1bef50e8/lib/shippo/api/api_object.rb:80: warning: already initialized constant Shippo::API::ApiObject::PROPS_ID /usr/local/Cellar/rbenv/1.1.0/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/shippo-ruby-client-b66c1bef50e8/lib/shippo/api/api_object.rb:80: warning: previous definition of PROPS_ID was here /usr/local/opt/rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/shippo-ruby-client-b66c1bef50e8/lib/shippo/api/api_object.rb:81: warning: already initialized constant Shippo::API::ApiObject::PROPS_CATEG /usr/local/Cellar/rbenv/1.1.0/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/shippo-ruby-client-b66c1bef50e8/lib/shippo/api/api_object.rb:81: warning: previous definition of PROPS_CATEG was here /usr/local/opt/rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/shippo-ruby-client-b66c1bef50e8/lib/shippo/api/api_object.rb:82: warning: already initialized constant Shippo::API::ApiObject::PROPS_EMAIL /usr/local/Cellar/rbenv/1.1.0/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/shippo-ruby-client-b66c1bef50e8/lib/shippo/api/api_object.rb:82: warning: previous definition of PROPS_EMAIL was here /usr/local/opt/rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/shippo-ruby-client-b66c1bef50e8/lib/shippo/api/api_object.rb:83: warning: already initialized constant Shippo::API::ApiObject::PROPS_TIMED /usr/local/Cellar/rbenv/1.1.0/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/shippo-ruby-client-b66c1bef50e8/lib/shippo/api/api_object.rb:83: warning: previous definition of PROPS_TIMED was here /usr/local/opt/rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/shippo-ruby-client-b66c1bef50e8/lib/shippo/api/api_object.rb:85: warning: already initialized constant Shippo::API::ApiObject::PROPS /usr/local/Cellar/rbenv/1.1.0/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/shippo-ruby-client-b66c1bef50e8/lib/shippo/api/api_object.rb:85: warning: previous definition of PROPS was here /usr/local/opt/rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/shippo-ruby-client-b66c1bef50e8/lib/shippo/api/api_object.rb:86: warning: already initialized constant Shippo::API::ApiObject::PROPS_AS_IS /usr/local/Cellar/rbenv/1.1.0/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/shippo-ruby-client-b66c1bef50e8/lib/shippo/api/api_object.rb:86: warning: previous definition of PROPS_AS_IS was here /usr/local/opt/rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/shippo-ruby-client-b66c1bef50e8/lib/shippo/api/transformers/list.rb:18: warning: already initialized constant Shippo::API::Transformers::List::MATCHERS /usr/local/Cellar/rbenv/1.1.0/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/shippo-ruby-client-b66c1bef50e8/lib/shippo/api/transformers/list.rb:18: warning: previous definition of MATCHERS was here
The text was updated successfully, but these errors were encountered: