Rails 7.0.4.2 - NoMethodError: undefined method `autoloader' for #<Rails::Application::Configuration...
thanosbellos opened this issue · 2 comments
Latest commit introduced an issue on Rails 7 apps.
How to reproduce the issue:
In a fresh Rails 7.0.4.2, ruby 3.2.1 app, i followed the instructions and run just a bin/rake sneakers:run
rake aborted!
NoMethodError: undefined method `autoloader' for #<Rails::Application::Configuration:0x0000000110efaf18 @root=#<Pathname:/Users/thanos/Desktop/rails-7-app>, @generators=#<Rails::Configuration::Generators:0x0000000110ebaaf8 @aliases={}, @options={:rails=>{:orm=>:active_record, :test_framework=>:test_unit, :integration_tool=>:test_unit, :system_tests=>:test_unit}, :active_record=>{:migration=>true, :timestamps=>true}, :test_unit=>{:fixture=>true, :fixture_replacement=>nil}}, @fallbacks={}, @templates=[], @colorize_logging=true, @api_only=false, @hidden_namespaces=[], @after_generate_callbacks=[]>, @middleware=#<ActionDispatch::MiddlewareStack:0x0000000112c38c38 @middlewares=[ActionDispatch::HostAuthorization, Rack::Sendfile, ActionDispatch::Static, ActionDispatch::Executor, ActionDispatch::ServerTiming, ActiveSupport::Cache::Strategy::LocalCache::Middleware, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, ActionDispatch::RemoteIp, Sprockets::Rails::QuietAssets, Rails::Rack::Logger, ActionDispatch::ShowExceptions, WebConsole::Middleware, ActionDispatch::DebugExceptions, ActionDispatch::ActionableExceptions, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ContentSecurityPolicy::Middleware, ActionDispatch::PermissionsPolicy::Middleware, Rack::Head, Rack::ConditionalGet, Rack::ETag, Rack::TempfileReaper]>, @javascript_path="javascript", @encoding=#<Encoding:UTF-8>, @allow_concurrency=nil, @consider_all_requests_local=true, @filter_parameters=[:passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn], @filter_redirect=[], @helpers_paths=["/Users/thanos/Desktop/rails-7-app/app/helpers", "/Users/thanos/.gem/ruby/3.2.1/gems/importmap-rails-1.1.5/app/helpers"], @hosts=[".localhost", #<IPAddr: IPv4:0.0.0.0/0.0.0.0>, #<IPAddr: IPv6:0000:0000:0000:0000:0000:0000:0000:0000/0000:0000:0000:0000:0000:0000:0000:0000>], @host_authorization={}, @public_file_server=#<ActiveSupport::OrderedOptions {:enabled=>true, :index_name=>"index"}>, @force_ssl=false, @ssl_options={:hsts=>{:subdomains=>true}}, @session_store=:cookie_store, @time_zone="UTC", @beginning_of_week=:monday, @log_level=:debug, @cache_store=:null_store, @railties_order=[:all], @relative_url_root=nil, @reload_classes_only_on_change=true, @file_watcher=ActiveSupport::FileUpdateChecker, @exceptions_app=nil, @autoflush_log=true, @log_formatter=#<ActiveSupport::Logger::SimpleFormatter:0x00000001111d6458 @datetime_format=nil>, @eager_load=false, @secret_key_base=nil, @api_only=false, @debug_exception_response_format=nil, @x=#<Rails::Application::Configuration::Custom:0x00000001111d5e68 @configurations={}>, @enable_dependency_loading=false, @read_encrypted_secrets=false, @content_security_policy=nil, @content_security_policy_report_only=false, @content_security_policy_nonce_generator=nil, @content_security_policy_nonce_directives=nil, @require_master_key=false, @loaded_config_version=7.0, @credentials=#<ActiveSupport::OrderedOptions {:content_path=>#<Pathname:/Users/thanos/Desktop/rails-7-app/config/credentials.yml.enc>, :key_path=>#<Pathname:/Users/thanos/Desktop/rails-7-app/config/master.key>}>, @disable_sandbox=false, @add_autoload_paths_to_load_path=true, @permissions_policy=nil, @rake_eager_load=false, @server_timing=true, @paths=#<Rails::Paths::Root:0x0000000111599ce8 @path=#<Pathname:/Users/thanos/Desktop/rails-7-app>, @root={"app"=>#<Rails::Paths::Path:0x0000000111c70ff8 @paths=["app"], @current="app", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob="{*,*/concerns}", @exclude=["assets", "javascript"], @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/assets"=>#<Rails::Paths::Path:0x000000011221f288 @paths=["app/assets"], @current="app/assets", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob="*", @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "app/controllers"=>#<Rails::Paths::Path:0x000000011221f1e8 @paths=["app/controllers"], @current="app/controllers", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/channels"=>#<Rails::Paths::Path:0x000000011221f148 @paths=["app/channels"], @current="app/channels", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/helpers"=>#<Rails::Paths::Path:0x000000011221f0a8 @paths=["app/helpers"], @current="app/helpers", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/models"=>#<Rails::Paths::Path:0x000000011221f008 @paths=["app/models"], @current="app/models", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/mailers"=>#<Rails::Paths::Path:0x000000011221ef68 @paths=["app/mailers"], @current="app/mailers", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=true, @autoload=false, @load_path=false>, "app/views"=>#<Rails::Paths::Path:0x000000011221eec8 @paths=["app/views"], @current="app/views", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "lib"=>#<Rails::Paths::Path:0x000000011221ee28 @paths=["lib"], @current="lib", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=true>, "lib/assets"=>#<Rails::Paths::Path:0x000000011221ed88 @paths=["lib/assets"], @current="lib/assets", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob="*", @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "lib/tasks"=>#<Rails::Paths::Path:0x000000011221ece8 @paths=["lib/tasks"], @current="lib/tasks", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob="**/*.rake", @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config"=>#<Rails::Paths::Path:0x000000011221ec48 @paths=["config"], @current="config", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/environments"=>#<Rails::Paths::Path:0x000000011221eba8 @paths=["config/environments"], @current="config/environments", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob="development.rb", @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/initializers"=>#<Rails::Paths::Path:0x000000011221eb08 @paths=["config/initializers"], @current="config/initializers", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob="**/*.rb", @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/locales"=>#<Rails::Paths::Path:0x000000011221ea68 @paths=["config/locales"], @current="config/locales", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob="**/*.{rb,yml}", @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/routes.rb"=>#<Rails::Paths::Path:0x000000011221e9c8 @paths=["config/routes.rb"], @current="config/routes.rb", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/routes"=>#<Rails::Paths::Path:0x000000011221e928 @paths=["config/routes"], @current="config/routes", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob="**/*.rb", @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "db"=>#<Rails::Paths::Path:0x000000011221e888 @paths=["db"], @current="db", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "db/migrate"=>#<Rails::Paths::Path:0x000000011221e7e8 @paths=["db/migrate"], @current="db/migrate", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "db/seeds.rb"=>#<Rails::Paths::Path:0x000000011221e748 @paths=["db/seeds.rb"], @current="db/seeds.rb", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "vendor"=>#<Rails::Paths::Path:0x000000011221e6a8 @paths=["vendor"], @current="vendor", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=true>, "vendor/assets"=>#<Rails::Paths::Path:0x000000011221e608 @paths=["vendor/assets"], @current="vendor/assets", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob="*", @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/database"=>#<Rails::Paths::Path:0x000000011221e568 @paths=["config/database.yml"], @current="config/database", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/secrets"=>#<Rails::Paths::Path:0x000000011221e4c8 @paths=["config"], @current="config/secrets", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob="secrets.yml{,.enc}", @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/environment"=>#<Rails::Paths::Path:0x000000011221e428 @paths=["config/environment.rb"], @current="config/environment", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "lib/templates"=>#<Rails::Paths::Path:0x000000011221e388 @paths=["lib/templates"], @current="lib/templates", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "log"=>#<Rails::Paths::Path:0x000000011221e2e8 @paths=["log/development.log"], @current="log", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "public"=>#<Rails::Paths::Path:0x000000011221e248 @paths=["public"], @current="public", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "public/javascripts"=>#<Rails::Paths::Path:0x000000011221e1a8 @paths=["public/javascripts"], @current="public/javascripts", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "public/stylesheets"=>#<Rails::Paths::Path:0x000000011221e108 @paths=["public/stylesheets"], @current="public/stylesheets", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "tmp"=>#<Rails::Paths::Path:0x000000011221e068 @paths=["tmp"], @current="tmp", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>, "config/cable"=>#<Rails::Paths::Path:0x0000000112a31f48 @paths=["config/cable.yml"], @current="config/cable", @root=#<Rails::Paths::Root:0x0000000111599ce8 ...>, @glob=nil, @exclude=nil, @autoload_once=false, @eager_load=false, @autoload=false, @load_path=false>}>, @cache_classes=false, @autoload_paths=[], @eager_load_paths=["/Users/thanos/Desktop/rails-7-app/app/channels", "/Users/thanos/Desktop/rails-7-app/app/controllers", "/Users/thanos/Desktop/rails-7-app/app/controllers/concerns", "/Users/thanos/Desktop/rails-7-app/app/helpers", "/Users/thanos/Desktop/rails-7-app/app/jobs", "/Users/thanos/Desktop/rails-7-app/app/mailers", "/Users/thanos/Desktop/rails-7-app/app/models", "/Users/thanos/Desktop/rails-7-app/app/models/concerns", "/Users/thanos/Desktop/rails-7-app/app/workers"], @autoload_once_paths=[], @session_options={:key=>"_rails7_app_session", :cookie_only=>true}>
/Users/thanos/.gem/ruby/3.2.1/gems/railties-7.0.4.2/lib/rails/railtie/configuration.rb:96:in `method_missing'
/Users/thanos/.gem/ruby/3.2.1/bundler/gems/sneakers-803d60deb729/lib/sneakers/tasks.rb:13:in `block (2 levels) in <main>'
A possible explanation
As per Rails Guides zeitwerk is the only autoloader mode and the config.autoloader =
method is deprecated. Although they don't state anything about whether the reader is still available, it seems it is not.
A possible solution
Maybe instead of using Rails.application.config.autoloader, we could use the following check as described in rails guides.
Rails.autoloaders.zeitwerk_enabled?
Or maybe use a different check based on rails version? I don't know what could more future proof.
@thanosbellos if Rails Guides recommend using a predicate, then we should do that. Please submit a PR?
Closed by #474.
@michaelklishin thanks for your quick response. Have a nice day!