Warnings when upgrading application from Rails 5 to Rails 7
Asked Answered
H

2

6

with a recent upgrade to rails 7.0.2 from rails 5.2, when ever i start a rails console or a rails server on dev mode i see these warnings

/Users/opensource/.rvm/gems/ruby-2.7.4/gems/digest-3.1.0/lib/digest.rb:20: warning: already initialized constant Digest::REQUIRE_MUTEX
/Users/opensource/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/digest.rb:6: warning: previous definition of REQUIRE_MUTEX was here
/Users/opensource/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/net/protocol.rb:66: warning: already initialized constant Net::ProtocRetryError
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/net-protocol-0.1.3/lib/net/protocol.rb:68: warning: previous definition of ProtocRetryError was here
/Users/opensource/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/net/protocol.rb:206: warning: already initialized constant Net::BufferedIO::BUFSIZE
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/net-protocol-0.1.3/lib/net/protocol.rb:208: warning: previous definition of BUFSIZE was here
/Users/opensource/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/net/protocol.rb:503: warning: already initialized constant Net::NetPrivate::Socket
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/net-protocol-0.1.3/lib/net/protocol.rb:504: warning: previous definition of Socket was here
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/apipie-rails-0.7.0/lib/apipie/extractor/recorder.rb:163: warning: Skipping set of ruby2_keywords flag for process (method accepts keywords or method

For what's its worth the warnings are not present when the application is on Rails 7.0 but only appear when the application is upgraded to Rails 7.0.2

I upgraded rails as per the guide

5.2 -> 6.0 -> 6.1 -> 7.0 -> 7.0.2

May be i missed something, anyways I could fix these? probably these would go away with a ruby / rails subsequent upgrade?

Thanks.

Heptateuch answered 4/4, 2022 at 7:51 Comment(3)
How did you update from Ruby on Rails 5.2 to 7.0.2? Did you do all the steps described in the Rails Guides? Did you update in smaller steps and fixed all issues in between? Or did you update in one step?Penis
yes, followed the steps mentioned in the guide and upgraded one version at a time. 5.2 -> 6.0 -> 6.1 -> 7.0 -> 7.0.2Heptateuch
I have the same issue. It appears it was introduced in rails 7.0.1. With 7.0.0 it doesn't have the issue.Capreolate
C
7

Rails 7.0.1 added some gem dependencies for standard lib stuff that would get removed in ruby 3.0. This unfortunately causes issue with ruby 2.7.6. You can get around this in several ways. Upgrading ruby will also upgrade bundler which fixes the issue. Upgrading bundler without ruby also works but I don't recommend it (better to point to the system version). A more conservative workaround is find the gems that are causing issues and list them on the top of your Gemfile. In my case I had to make sure that the gem version was the same as the default ruby gem version. For example, I had to make the Gemfile have gem "uri", "0.10.0". A good way to debug what is causing these is put this at the top of your Gemfile:

Warning.module_eval do
  alias_method :original_warn, :warn

  def warn(msg)
    if msg.match?(/already initialized constant/)
      raise msg
    else
      original_warn(msg)
    end
  end
end

That way you get a stacktrace of the places that are requiring stdlib files that also have a conflicting rubygem.

Capreolate answered 19/4, 2022 at 15:57 Comment(1)
run bundle updatePortal
M
-1

It looks like these are all constants defined in dependency code gems. Running bundle clean --force or updating dependencies with bundle update and then running the bundle clean --force has worked for some when experiencing this issue.

Mystic answered 4/4, 2022 at 21:32 Comment(1)
bundle clean --force removed the "already initialized constant" message for me.Lollar

© 2022 - 2024 — McMap. All rights reserved.