Rails 6 Zeitwerk (default mode)

…/lib/forest_liana/collections/variant.rb

# frozen_string_literal: true

module Forest
  class Variant
    include ForestLiana::Collection

    collection :Variant

    field :gid, type: 'String' do
      object.gid
    end

    field :identifier, type: 'String' do
      object.identifier
    end
  end
end

ends up in

Zeitwerk::NameError:
  expected file /Users/daniel/GitHub/project-name/lib/forest_liana/collections/variant.rb to define constant ForestLiana::Collections::Variant, but didn't
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/zeitwerk-2.4.0/lib/zeitwerk/loader/callbacks.rb:17:in `on_file_autoloaded'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/zeitwerk-2.4.0/lib/zeitwerk/kernel.rb:28:in `block in require'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/zeitwerk-2.4.0/lib/zeitwerk/kernel.rb:27:in `tap'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/zeitwerk-2.4.0/lib/zeitwerk/kernel.rb:27:in `require'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/zeitwerk-2.4.0/lib/zeitwerk/loader.rb:392:in `const_get'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/zeitwerk-2.4.0/lib/zeitwerk/loader.rb:392:in `block (2 levels) in eager_load'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/zeitwerk-2.4.0/lib/zeitwerk/loader.rb:742:in `block in ls'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/zeitwerk-2.4.0/lib/zeitwerk/loader.rb:734:in `foreach'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/zeitwerk-2.4.0/lib/zeitwerk/loader.rb:734:in `ls'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/zeitwerk-2.4.0/lib/zeitwerk/loader.rb:387:in `block in eager_load'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/zeitwerk-2.4.0/lib/zeitwerk/loader.rb:376:in `synchronize'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/zeitwerk-2.4.0/lib/zeitwerk/loader.rb:376:in `eager_load'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/zeitwerk-2.4.0/lib/zeitwerk/loader.rb:494:in `each'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/zeitwerk-2.4.0/lib/zeitwerk/loader.rb:494:in `eager_load_all'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/forest_liana-5.2.2/lib/forest_liana/engine.rb:61:in `eager_load_active_record_descendants'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/railties-6.0.3.2/lib/rails/railtie.rb:190:in `public_send'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/railties-6.0.3.2/lib/rails/railtie.rb:190:in `method_missing'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/forest_liana-5.2.2/lib/forest_liana/engine.rb:73:in `block in <class:Engine>'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:68:in `block in execute_hook'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:51:in `each'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/railties-6.0.3.2/lib/rails/application/finisher.rb:129:in `block in <module:Finisher>'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/railties-6.0.3.2/lib/rails/initializable.rb:32:in `instance_exec'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/railties-6.0.3.2/lib/rails/initializable.rb:32:in `run'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/railties-6.0.3.2/lib/rails/initializable.rb:61:in `block in run_initializers'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/railties-6.0.3.2/lib/rails/initializable.rb:60:in `run_initializers'
# /Users/daniel/.rvm/gems/ruby-2.6.5/gems/railties-6.0.3.2/lib/rails/application.rb:363:in `initialize!'
# ./config/environment.rb:7:in `<top (required)>'
# ./spec/rails_helper.rb:4:in `require'
# ./spec/rails_helper.rb:4:in `<top (required)>'
# ./spec/graphql/types/shared_asset_type_spec.rb:3:in `require'
# ./spec/graphql/types/shared_asset_type_spec.rb:3:in `<top (required)>'

How should I change this to work with forest and with rails 6 zeitwerk mode that is the default mode of rails 6?

Hello @sayduck-daniel,

Welcome to the Forest Admin community.

I’ll loop with the team to see when we can handle this properly, but for now telling Zeitwerk to ignore this directory might be the easiest way for you.

Can you try adding Rails.autoloaders.main.ignore(Rails.root.join('lib/forest_liana')) to your config/application.rb?

Let me know if this work for you.