fxn/zeitwerk

Zeitwerk::NameError for gem VERSION

sajan45 opened this issue · 8 comments

Hi @fxn . I am getting the same error as #284 but for ActionCable now as I am trying to upgrade Rails. I know this probably is not caused by Zeitwerk but I would really appreciate it if you could suggest some patches for this. ActionCable is using the recommended for_gem setup, unlike Gruf in the last issue.

I can move this to Rails issues, if you feel this belongs there instead of here.

Below is the backtrace:

/bundle/lib/ruby/3.1.0/gems/actioncable-7.1.3.2/lib/action_cable/version.rb to define constant ActionCable::VERSION, but didn't (Zeitwerk::NameError)

      raise Zeitwerk::NameError.new(msg, cref.last)
      ^^^^^
	from /bundle/lib/ruby/3.1.0/gems/zeitwerk-2.6.13/lib/zeitwerk/kernel.rb:27:in `require'
	from /bundle/lib/ruby/3.1.0/gems/actioncable-7.1.3.2/lib/action_cable/gem_version.rb:9:in `<module:ActionCable>'
	from /bundle/lib/ruby/3.1.0/gems/actioncable-7.1.3.2/lib/action_cable/gem_version.rb:3:in `<top (required)>'
	from /bundle/lib/ruby/3.1.0/gems/actioncable-7.1.3.2/lib/action_cable/version.rb:3:in `require_relative'
	from /bundle/lib/ruby/3.1.0/gems/actioncable-7.1.3.2/lib/action_cable/version.rb:3:in `<top (required)>'
	from /bundle/lib/ruby/3.1.0/gems/actioncable-7.1.3.2/lib/action_cable.rb:49:in `require_relative'
	from /bundle/lib/ruby/3.1.0/gems/actioncable-7.1.3.2/lib/action_cable.rb:49:in `<module:ActionCable>'
	from /bundle/lib/ruby/3.1.0/gems/actioncable-7.1.3.2/lib/action_cable.rb:48:in `<top (required)>'
	from <internal:/usr/local/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from <internal:/usr/local/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /bundle/lib/ruby/3.1.0/gems/actioncable-7.1.3.2/lib/action_cable/engine.rb:4:in `<top (required)>'
	from <internal:/usr/local/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from <internal:/usr/local/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /c3d/my_app/config/application.rb:18:in `<top (required)>'              # require 'action_cable/engine'
	from <internal:/usr/local/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from <internal:/usr/local/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /c3d/my_app/config/environment.rb:6:in `<top (required)>'
	from <internal:/usr/local/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from <internal:/usr/local/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /c3d/my_app/bin/rails:3:in `<top (required)>'
	from /c3d/my_app/bin/rails_test:6:in `load'
	from /c3d/my_app/bin/rails_test:6:in `<main>'
fxn commented

@sajan45 how did you get this exception?

The backtrace is from the rails test command (using a rails_test file which sets a few ENV and loads bin/rails), but I am getting the same exception for the rake command and rails console as well. We also use Passenger + Nginx for the development environment, so I have not tried anything like rails server.

Our current Rails version is 7.0.8.1, I am trying to upgrade it to 7.1.3.2

fxn commented

Action Cable is used by many Rails applications and this has not been reported before, AFAIK. Do you think you could get a minimal application where the error is reproducible?

(This is most likely a Rails issue, but let's continue here by now.)

I will try to create a minimal app and get back to you in a couple of days.

I could not replicate this in a new app. So, I am closing this until I can replicate this in a new setup. Next time, I will create the issue in the Rails repo. Thanks.

@fxn I have created a PR on the rails repo that fixes this rails/rails#52184. Can you please take a look at that? I guess there were a couple of issues, the problem with using __dir__ as the path prefix and then the unconventional version.rb file that does not define the ActionCable::VERSION. After your last change to the loader to ignore the version.rb, replacing the __dir__ with symlink path works for me.

fxn commented

Ahhh, symlinks. Makes sense, thanks for the patch!