Home > OS >  Upgrading to from rails 5 to 6 and zeitwerk
Upgrading to from rails 5 to 6 and zeitwerk

Time:12-10

We have a rails 5.2.8.1 app and a trying to upgrade to rails 6.1. We have managed to make the application run locally with only minor problems.

However, pushing to our ci (circleCI) we get errors in precompiling the assets. The error is that the zeitwerk loader (load once) wants to manage actiontext-6.1.7/app/helpers which is already managed by the default main loader.

The weird thing is we do not use the load once loader at all..

loader setup in application.rb

    config.autoload_paths  = %W[
      #{config.root}/lib
      #{config.root}/lib/simple_form
      #{config.root}/app/jobs
      #{config.root}/app/jobs/concerns
      #{config.root}/app/controllers/concerns
      #{config.root}/app/mailers/concerns
      #{config.root}/app/models/concerns
      #{config.root}/app/models/reports
      #{config.root}/app/services/pdf_data
      #{config.root}/app/presenters
      #{config.root}/app/assets/templates
      #{config.root}/app/event_handlers
      #{config.root}/app/queries
      #{config.root}/app/concepts
      #{config.root}/vendor/
      #{config.root}/app/pdfs
    ]

    config.eager_load_paths  = %W[
      #{config.root}/lib
    ]

error printout:

#!/bin/bash -eo pipefail
WEBPACKER_PRECOMPILE=false RAILS_NO_DB=true bundle exec rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
rake aborted!
Zeitwerk::Error: loader

#<Zeitwerk::Loader:0x000055eb81710b98
 @autoloaded_dirs=[],
 @autoloads={},
 @collapse_dirs=#<Set: {}>,
 @collapse_glob_patterns=#<Set: {}>,
 @eager_load_exclusions=#<Set: {}>,
 @eager_loaded=false,
 @ignored_glob_patterns=#<Set: {}>,
 @ignored_paths=#<Set: {}>,
 @inflector=ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector,
 @initialized_at=2022-12-07 14:27:29.123263169  0000,
 @logger=nil,
 @mutex=#<Thread::Mutex:0x000055eb81710738>,
 @mutex2=#<Thread::Mutex:0x000055eb81710710>,
 @namespace_dirs={},
 @on_load_callbacks={},
 @on_setup_callbacks=[],
 @on_unload_callbacks={},
 @reloading_enabled=false,
 @roots={},
 @setup=false,
 @shadowed_files=#<Set: {}>,
 @tag="rails.once",
 @to_unload={}>


wants to manage directory /home/circleci/flightlogger-rails/vendor/bundle/ruby/2.7.0/gems/actiontext-6.1.7/app/helpers, which is already managed by

#<Zeitwerk::Loader:0x000055eb81712f88
 @autoloaded_dirs=[],
 @autoloads={},
 @collapse_dirs=#<Set: {}>,
 @collapse_glob_patterns=#<Set: {}>,
 @eager_load_exclusions=
  #<Set: {"/home/circleci/flightlogger-rails/lib/simple_form",
   "/home/circleci/flightlogger-rails/app/models/reports",
   "/home/circleci/flightlogger-rails/app/assets/templates",
   "/home/circleci/flightlogger-rails/vendor"}>,
 @eager_loaded=false,
 @ignored_glob_patterns=#<Set: {}>,
 @ignored_paths=#<Set: {}>,
 @inflector=ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector,
 @initialized_at=2022-12-07 14:27:29.122727016  0000,
 @logger=nil,
 @mutex=#<Thread::Mutex:0x000055eb81712ab0>,
 @mutex2=#<Thread::Mutex:0x000055eb81712a88>,
 @namespace_dirs={},
 @on_load_callbacks={},
 @on_setup_callbacks=[],
 @on_unload_callbacks={},
 @reloading_enabled=false,
 @roots=
  {"/home/circleci/flightlogger-rails/lib"=>Object,
   "/home/circleci/flightlogger-rails/lib/simple_form"=>Object,
   "/home/circleci/flightlogger-rails/app/jobs"=>Object,
   "/home/circleci/flightlogger-rails/app/jobs/concerns"=>Object,
   "/home/circleci/flightlogger-rails/app/controllers/concerns"=>Object,
   "/home/circleci/flightlogger-rails/app/mailers/concerns"=>Object,
   "/home/circleci/flightlogger-rails/app/models/concerns"=>Object,
   "/home/circleci/flightlogger-rails/app/models/reports"=>Object,
   "/home/circleci/flightlogger-rails/app/presenters"=>Object,
   "/home/circleci/flightlogger-rails/app/assets/templates"=>Object,
   "/home/circleci/flightlogger-rails/app/event_handlers"=>Object,
   "/home/circleci/flightlogger-rails/app/queries"=>Object,
   "/home/circleci/flightlogger-rails/app/concepts"=>Object,
   "/home/circleci/flightlogger-rails/vendor"=>Object,
   "/home/circleci/flightlogger-rails/app/pdfs"=>Object,
   "/home/circleci/flightlogger-rails/app/associations"=>Object,
   "/home/circleci/flightlogger-rails/app/channels"=>Object,
   "/home/circleci/flightlogger-rails/app/controllers"=>Object,
   "/home/circleci/flightlogger-rails/app/decorators"=>Object,
   "/home/circleci/flightlogger-rails/app/forms"=>Object,
   "/home/circleci/flightlogger-rails/app/graphql"=>Object,
   "/home/circleci/flightlogger-rails/app/graphql/concerns"=>Object,
   "/home/circleci/flightlogger-rails/app/helpers"=>Object,
   "/home/circleci/flightlogger-rails/app/interactors"=>Object,
   "/home/circleci/flightlogger-rails/app/mailers"=>Object,
   "/home/circleci/flightlogger-rails/app/models"=>Object,
   "/home/circleci/flightlogger-rails/app/permitters"=>Object,
   "/home/circleci/flightlogger-rails/app/policies"=>Object,
   "/home/circleci/flightlogger-rails/app/public_api"=>Object,
   "/home/circleci/flightlogger-rails/app/serializers"=>Object,
   "/home/circleci/flightlogger-rails/app/services"=>Object,
   "/home/circleci/flightlogger-rails/app/validators"=>Object,
   "/home/circleci/flightlogger-rails/vendor/bundle/ruby/2.7.0/gems/jquery-minicolors-rails-2.2.6.2/app/inputs"=>
    Object,
   "/home/circleci/flightlogger-rails/engines/sms/app/concerns"=>Object,
   "/home/circleci/flightlogger-rails/engines/sms/app/controllers"=>Object,
   "/home/circleci/flightlogger-rails/engines/sms/app/helpers"=>Object,
   "/home/circleci/flightlogger-rails/engines/sms/app/inputs"=>Object,
   "/home/circleci/flightlogger-rails/engines/sms/app/mailers"=>Object,
   "/home/circleci/flightlogger-rails/engines/sms/app/models"=>Object,
   "/home/circleci/flightlogger-rails/vendor/bundle/ruby/2.7.0/gems/sentry-rails-5.6.0/app/jobs"=>
    Object,
   "/home/circleci/flightlogger-rails/vendor/bundle/ruby/2.7.0/gems/react_on_rails-13.1.0/app/helpers"=>
    Object},
 @setup=false,
 @shadowed_files=#<Set: {}>,
 @tag="rails.main",
 @to_unload={}>

CodePudding user response:

The problem is that vendor is added to the autoload paths of the main autoloader. It should not be there.

Action Text configures the once autoloader (here), but with your configuration it cannot do that because main manages vendor (and therefore all its descendants).

Your configuration should not be adding vendor, because vendor/bundle is not intended to define a Bundle module, right? That directory is not meant to be autoloaded by the application.

Dependencies load themselves.

In addition to removing vendor from that configuration, you should also remove these redundant directories that are automatically added by Rails:

#{config.root}/app/jobs
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
#{config.root}/app/presenters
#{config.root}/app/event_handlers
#{config.root}/app/queries
#{config.root}/app/concepts
#{config.root}/app/pdfs
  • Related