Skip to content

NoMethodError exception with sprockets-rails 3.5.0 #524

@benubois

Description

@benubois

Hello,

After upgrading to 3.5.0, I'm seeing a new exception in a rails 7.1.3.4 app with config.load_defaults 6.1.

$ bundle exec rails assets:precompile --trace
bin/rails aborted!
NoMethodError: undefined method `deprecator' for module Sprockets::Rails (NoMethodError)

      app.deprecators[:sprockets_rails] = Sprockets::Rails.deprecator if app.respond_to?(:deprecators)
                                                          ^^^^^^^^^^^
Did you mean?  deprecate
/lib/ruby/gems/3.3.0/gems/sprockets-rails-3.5.0/lib/sprockets/railtie.rb:129:in `block in <class:Railtie>'

initializer "sprockets-rails.deprecator" do |app|
app.deprecators[:sprockets_rails] = Sprockets::Rails.deprecator if app.respond_to?(:deprecators)
end

There's something happening with the load order because if I add the new deprecator method before Rails.application.initialize!, then no exception is raised.

environment.rb

# Load the Rails application.
require_relative "application"

module Sprockets
  module Rails
    def self.deprecator
      @deprecator ||= ActiveSupport::Deprecation.new("4.0", "Sprockets::Rails")
    end
  end
end

# Initialize the Rails application.
Rails.application.initialize!

I'll continue to look into this, but wanted to post in case there's something obvious to someone who understands this better.

Thanks!

Full Backtrace

$ bundle exec rails assets:precompile --trace
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
bin/rails aborted!
NoMethodError: undefined method `deprecator' for module Sprockets::Rails (NoMethodError)

      app.deprecators[:sprockets_rails] = Sprockets::Rails.deprecator if app.respond_to?(:deprecators)
                                                          ^^^^^^^^^^^
Did you mean?  deprecate
/lib/ruby/gems/3.3.0/gems/sprockets-rails-3.5.0/lib/sprockets/railtie.rb:129:in `block in <class:Railtie>'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/initializable.rb:32:in `instance_exec'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/initializable.rb:32:in `run'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/initializable.rb:61:in `block in run_initializers'
/lib/ruby/3.3.0/tsort.rb:231:in `block in tsort_each'
/lib/ruby/3.3.0/tsort.rb:353:in `block (2 levels) in each_strongly_connected_component'
/lib/ruby/3.3.0/tsort.rb:434:in `each_strongly_connected_component_from'
/lib/ruby/3.3.0/tsort.rb:352:in `block in each_strongly_connected_component'
/lib/ruby/3.3.0/tsort.rb:350:in `each'
/lib/ruby/3.3.0/tsort.rb:350:in `call'
/lib/ruby/3.3.0/tsort.rb:350:in `each_strongly_connected_component'
/lib/ruby/3.3.0/tsort.rb:229:in `tsort_each'
/lib/ruby/3.3.0/tsort.rb:208:in `tsort_each'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/initializable.rb:60:in `run_initializers'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/application.rb:426:in `initialize!'
/Users/ben/Sites/feedbin/config/environment.rb:5:in `<main>'
/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/lib/ruby/gems/3.3.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.15/lib/zeitwerk/kernel.rb:34:in `require'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/application.rb:402:in `require_environment!'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/application.rb:588:in `block in run_tasks_blocks'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `block in execute'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `each'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `execute'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:199:in `synchronize'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:188:in `invoke'
/lib/ruby/gems/3.3.0/gems/sprockets-rails-3.5.0/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `block in execute'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `each'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `execute'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:199:in `synchronize'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:243:in `block in invoke_prerequisites'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:241:in `each'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:241:in `invoke_prerequisites'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:199:in `synchronize'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/task.rb:188:in `invoke'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/application.rb:188:in `invoke_task'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `block (2 levels) in top_level'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `each'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `block in top_level'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/application.rb:147:in `run_with_threads'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/application.rb:132:in `top_level'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/commands/rake/rake_command.rb:27:in `block (2 levels) in perform'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/application.rb:214:in `standard_exception_handling'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/commands/rake/rake_command.rb:27:in `block in perform'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/commands/rake/rake_command.rb:44:in `block in with_rake'
/lib/ruby/gems/3.3.0/gems/rake-13.2.1/lib/rake/rake_module.rb:59:in `with_application'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/commands/rake/rake_command.rb:41:in `with_rake'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/command.rb:156:in `invoke_rake'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/command.rb:73:in `block in invoke'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/command.rb:149:in `with_argv'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/command.rb:69:in `invoke'
/lib/ruby/gems/3.3.0/gems/railties-7.1.3.4/lib/rails/commands.rb:18:in `<main>'
/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/lib/ruby/gems/3.3.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions