Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError exception with sprockets-rails 3.5.0 #524

Closed
benubois opened this issue Jun 6, 2024 · 10 comments · Fixed by #525
Closed

NoMethodError exception with sprockets-rails 3.5.0 #524

benubois opened this issue Jun 6, 2024 · 10 comments · Fixed by #525

Comments

@benubois
Copy link

benubois commented Jun 6, 2024

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
@sl0thentr0py
Copy link

also seeing this in our CI
https://github.com/getsentry/sentry-ruby/actions/runs/9400631851/job/25890677265?pr=2319#step:5:1317

mamhoff added a commit to mamhoff/sprockets-rails that referenced this issue Jun 6, 2024
With the release of sprockets-rails 3.5.0, our local test suite breaks
with

```
NoMethodError:
  undefined method `deprecator' for Sprockets::Rails:Module
 /home/circleci/solidus/vendor/bundle/ruby/3.2.0/gems/sprockets-rails-3.5.0/lib/sprockets/railtie.rb:129:in `block in <class:Railtie>'
```

This should fix that by explicitly requiring the
`Sprockets::Rails.deprecator` in both `lib/sprockets/rails.rb` and
`lib/sprockets/railtie.rb`.

Should fix rails#524
mamhoff added a commit to mamhoff/solidus that referenced this issue Jun 6, 2024
sprockets-rails 3.5.0 breaks our test suite.

See rails/sprockets-rails#524
and rails/sprockets-rails#525
@joemsak
Copy link

joemsak commented Jun 6, 2024

Started happening in our github actions during zeitwerk:check - just updated to Rails 7.1.3.4

@ccasabona
Copy link

ccasabona commented Jun 6, 2024

I m having the same problem. By chance I had another project where I did not get this exception after upgrading to 3.5.0.

All projects use dartsass. On one project, sprockets-rails 3.5.0 worked. By experimentation, I found that I do not get this exception if I list sprockets-rails before dartsass-sprockets in the Gemfile as such:

# Use SCSS for stylesheets
gem 'dartsass-rails'
gem 'sprockets-rails', '~> 3.5.0'
gem 'dartsass-sprockets'
gem 'sass-embedded'

@joemsak
Copy link

joemsak commented Jun 6, 2024

Fix from @ccasabona seems to have worked for us, too.

gem "sprockets-rails", "~> 3.4.2"
gem "sprockets", "~> 3.7.3"
gem "sass-rails", "~> 6.0.0"

We didn't have sprockets-rails in our Gemfile. I listed it above sass-rails and now things work again.
(we don't have dartsass, dartsass-rails, or sass-embedded)

Looks like we have 3.4 instead of 3.5 now, that's probably what fixed it!

So the fix in environment.rb by @benubois works for 3.5.0 and the fix in the Gemfile for @ccasabona is probably the same as me: I bet your bundler installed 3.4.x

@ccasabona
Copy link

To be clear, listing sprockets-rails before dartsass-sprockets or spockets works when using sprockets-rails 3.5.0. If you're using 3.4.2, it does not appear to matter.

@joemsak
Copy link

joemsak commented Jun 6, 2024

Sounds good. I didn't specify a version and got what bundler gave me.

@ur5us
Copy link

ur5us commented Jun 7, 2024

For one of my apps, the order in the Gemfile is as suggested by @ccasabona and yet it was failing to boot. What fixes it is not following part of the installation instructions, specifically leave out the :require => 'sprockets/railtie' part from

# Asset handling & front-end concerns
gem 'sprockets-rails', :require => 'sprockets/railtie'
gem 'shakapacker', '8.0.0'
gem 'sassc-rails'
gem 'breakpoint'
gem 'autoprefixer-rails'
gem 'terser'
gem 'csso-rails'
gem 'turbo-rails'

Looking at the file/directory structure I can see why having :require => 'sprockets/railtie' would be an issue as there’s no require 'sprockets/rails' in sprockets/railtie, yet I’m more confused than before. Everything seems to work despite sassc-rails requiring sprockets/railtie but not sprockets/rails after removing that require from the Gemfile. So I assume something else is requiring it so that by the time sprocket-rails’ initializer is called it’s all been loaded.

yahonda added a commit to yahonda/rails that referenced this issue Jun 7, 2024
This commit pins `sprockets-rails` version to 3.4.2
until rails/sprockets-rails#524 is fixed.

Refer to rails#52038
mamhoff added a commit to mamhoff/sprockets-rails that referenced this issue Jun 7, 2024
With the release of sprockets-rails 3.5.0, our local test suite breaks
with

```
NoMethodError:
  undefined method `deprecator' for Sprockets::Rails:Module
 /home/circleci/solidus/vendor/bundle/ruby/3.2.0/gems/sprockets-rails-3.5.0/lib/sprockets/railtie.rb:129:in `block in <class:Railtie>'
```

This should fix that by explicitly requiring the
`Sprockets::Rails.deprecator` in both `lib/sprockets/rails.rb` and
`lib/sprockets/railtie.rb`.

Should fix rails#524
tvdeyen added a commit to tvdeyen/alchemy-devise that referenced this issue Jun 7, 2024
@casperisfine
Copy link

Looking into it.

casperisfine pushed a commit to Shopify/rails that referenced this issue Jun 7, 2024
casperisfine pushed a commit to Shopify/rails that referenced this issue Jun 7, 2024
@ccasabona
Copy link

Thank you for your work in releasing 3.5.1. This version is working on our Rails 7.1.3.4 and 7.2.beta2 projects. I was able to go back to not listing sprockets-rails in the gemfile as before.

tvdeyen added a commit to tvdeyen/alchemy_cms that referenced this issue Jun 7, 2024
@benubois
Copy link
Author

benubois commented Jun 7, 2024

This is resolved with 3.5.1. Thanks @mamhoff & @byroot!

tvdeyen added a commit to tvdeyen/alchemy_cms that referenced this issue Jun 7, 2024
xjunior pushed a commit to xjunior/rails that referenced this issue Jun 9, 2024
This commit pins `sprockets-rails` version to 3.4.2
until rails/sprockets-rails#524 is fixed.

Refer to rails#52038
xjunior pushed a commit to xjunior/rails that referenced this issue Jun 9, 2024
Set2005 pushed a commit to Set2005/fix-association-initialize-order that referenced this issue Jul 8, 2024
This commit pins `sprockets-rails` version to 3.4.2
until rails/sprockets-rails#524 is fixed.

Refer to rails#52038
Set2005 pushed a commit to Set2005/fix-association-initialize-order that referenced this issue Jul 8, 2024
DanielaVelasquez pushed a commit to DanielaVelasquez/rails that referenced this issue Oct 3, 2024
This commit pins `sprockets-rails` version to 3.4.2
until rails/sprockets-rails#524 is fixed.

Refer to rails#52038
DanielaVelasquez pushed a commit to DanielaVelasquez/rails that referenced this issue Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants