Skip to content

NameError: uninitialized constant MyGem::Foo::Bar when using Zeitwerk #8853

@bolshakov

Description

@bolshakov

Environment Information

  • Ubuntu 24.04.2
  • jruby 10.0.0.1 (3.4.2) 2025-05-07 79cf1e4 OpenJDK 64-Bit Server VM 21.0.7+6-LTS on 21.0.7+6-LTS +indy +jit [x86_64-linux]

Here is the link to the failing pipeline: https://github.com/bolshakov/stoplight/actions/runs/15330860361/job/43137018456?pr=329

I added JRuby 10.0.0.1 to my test suite and the specs fail due to not loaded constants:

An error occurred while loading ./spec/properties/color_spec.rb.
Failure/Error: include Configurable

NameError:
  uninitialized constant Stoplight::Light::Configurable
# ./lib/stoplight/light.rb:7:in '<class:Light>'
# ./lib/stoplight/light.rb:6:in '<module:Stoplight>'
# ./lib/stoplight/light.rb:3:in '<main>'
# ./vendor/bundle/jruby/3.4.0/gems/zeitwerk-2.7.3/lib/zeitwerk/core_ext/kernel.rb:26:in 'require'
# ./vendor/bundle/jruby/3.4.0/gems/zeitwerk-2.7.3/lib/zeitwerk/loader/eager_load.rb:180:in 'block in actual_eager_load_dir'
# ./vendor/bundle/jruby/3.4.0/gems/zeitwerk-2.7.3/lib/zeitwerk/loader/helpers.rb:47:in 'block in ls'
# ./vendor/bundle/jruby/3.4.0/gems/zeitwerk-2.7.3/lib/zeitwerk/loader/helpers.rb:25:in 'ls'
# ./vendor/bundle/jruby/3.4.0/gems/zeitwerk-2.7.3/lib/zeitwerk/loader/eager_load.rb:168:in 'actual_eager_load_dir'
# ./vendor/bundle/jruby/3.4.0/gems/zeitwerk-2.7.3/lib/zeitwerk/loader/eager_load.rb:17:in 'block in eager_load'
# ./vendor/bundle/jruby/3.4.0/gems/zeitwerk-2.7.3/lib/zeitwerk/loader/eager_load.rb:16:in 'block in eager_load'
# ./vendor/bundle/jruby/3.4.0/gems/zeitwerk-2.7.3/lib/zeitwerk/loader/eager_load.rb:10:in 'eager_load'
# ./lib/stoplight.rb:158:in '<main>'
# ./spec/spec_helper.rb:5:in '<main>'
# ./spec/properties/color_spec.rb:5:in '<main>'

This is how the Zeitwerk configuration looks:

loader = Zeitwerk::Loader.for_gem
loader.inflector.inflect("io" => "IO")
loader.ignore("#{__dir__}/stoplight/rspec.rb", "#{__dir__}/stoplight/rspec")
loader.setup

module Stoplight
  # ...
end

loader.eager_load

I tried it without eager_load, and I faced a similar error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions