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

Incompatible with sprockets-rails 3.0? #135

Open
dbackeus opened this issue Jan 21, 2016 · 28 comments · Fixed by #140
Open

Incompatible with sprockets-rails 3.0? #135

dbackeus opened this issue Jan 21, 2016 · 28 comments · Fixed by #140

Comments

@dbackeus
Copy link

After upgrading sprockets-rails to 3.0 I get the following boot time error:

.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/browserify-rails-2.2.1/lib/browserify-rails/railtie.rb:35:in `block in <class:Railtie>': undefined method `register_postprocessor' for nil:NilClass (NoMethodError)
    from .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `instance_exec'
    from .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `run'
    from .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:55:in `block in run_initializers'
    from .rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
    from .rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from .rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
    from .rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from .rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `each'
    from .rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `call'
    from .rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
    from .rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
    from .rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
    from .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:54:in `run_initializers'
    from .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/application.rb:352:in `initialize!'
    from development/rails/mndx-web/config/environment.rb:5:in `<top (required)>'
    from development/rails/mndx-web/spec/rails_helper.rb:4:in `require'
    from development/rails/mndx-web/spec/rails_helper.rb:4:in `<top (required)>'
    from development/rails/mndx-web/spec/adapters/mndx_users_adapter_spec.rb:1:in `require'
    from development/rails/mndx-web/spec/adapters/mndx_users_adapter_spec.rb:1:in `<top (required)>'
    from .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1361:in `load'
    from .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1361:in `block in load_spec_files'
    from .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1359:in `each'
    from .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1359:in `load_spec_files'
    from .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:102:in `setup'
    from .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:88:in `run'
    from .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:73:in `run'
    from .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:41:in `invoke'
    from .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/exe/rspec:4:in `<top (required)>'
    from .rbenv/versions/2.2.3/bin/rspec:23:in `load'
    from .rbenv/versions/2.2.3/bin/rspec:23:in `<main>'
@cymen
Copy link
Member

cymen commented Jan 21, 2016

What version of browserify-rails are you using?

@cymen
Copy link
Member

cymen commented Jan 21, 2016

There is a bit of code that branches with a check to see if config responds to assets invocation:

    if config.respond_to?(:assets)
      config.assets.configure do |env|
        load_granular_configuration
        env.register_postprocessor "application/javascript", BrowserifyRails::BrowserifyProcessor
      end
    else
      initializer :setup_browserify do |app|
        load_granular_configuration
        app.assets.register_postprocessor "application/javascript", BrowserifyRails::BrowserifyProcessor
      end
    end

Maybe with Sprockets 3.0 config does not respond to assets. According to the sprocket-rails README, it should use env.register_preprocessor so if config doesn't respond to assets, it may fall through to try to do the wrong configuration method (app.register_preprocessor).

@cymen
Copy link
Member

cymen commented Jan 21, 2016

If so, the fix may be simply changing:

if config.respond_to?(:assets)

To something like:

if config.respond_to?(:assets) || is_sprockets_3_or_higher

One would need to implement is_sprockets_3_or_higher of course.

@cymen
Copy link
Member

cymen commented Jan 21, 2016

One other thought is it could be your set of gems. Did you upgrade anything else when you upgraded sprocket-rails? If you haven't, it might be worth trying an upgraded railties too.

@dbackeus
Copy link
Author

I got the same error on all browserify-rails from version 1.5.0 to 2.2.1 (the stacktrace above is 2.2.1 as can be found out through looking at the rubygems directories).

All other rails gems etc are at the latest version already.

Not sure how to reach the env since config.assets.configure will break on not responding to .assets.

@cymen
Copy link
Member

cymen commented Feb 3, 2016

I should clarify that PRs for this are welcomed if anyone has time to dig into it. I don't expect to any time soon :(.

@AndyObtiva
Copy link

I got the same issue when I upgraded from Rails 4.2.1 to 4.2.5.1.
browserify-rails is at version 1.2.0

Full stack trace:

Users/User/.rvm/gems/ruby-2.2.3@backbone_example/gems/browserify-rails-1.2.0/lib/browserify-rails/railtie.rb:33:in `block in <class:Railtie>': undefined method `register_postprocessor' for nil:NilClass (NoMethodError)
    from /Users/User/.rvm/gems/ruby-2.2.3@backbone_example/gems/railties-4.2.5.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/User/.rvm/gems/ruby-2.2.3@backbone_example/gems/railties-4.2.5.1/lib/rails/initializable.rb:30:in `run'
    from /Users/User/.rvm/gems/ruby-2.2.3@backbone_example/gems/railties-4.2.5.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/User/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
    from /Users/User/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /Users/User/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
    from /Users/User/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /Users/User/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `each'
    from /Users/User/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `call'
    from /Users/User/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
    from /Users/User/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
    from /Users/User/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
    from /Users/User/.rvm/gems/ruby-2.2.3@backbone_example/gems/railties-4.2.5.1/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/User/.rvm/gems/ruby-2.2.3@backbone_example/gems/railties-4.2.5.1/lib/rails/application.rb:352:in `initialize!'
    from /Users/User/code/backbone_example/config/environment.rb:5:in `<top (required)>'
    from /Users/User/.rvm/gems/ruby-2.2.3@backbone_example/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require'
    from /Users/User/.rvm/gems/ruby-2.2.3@backbone_example/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `block in require'
    from /Users/User/.rvm/gems/ruby-2.2.3@backbone_example/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/User/.rvm/gems/ruby-2.2.3@backbone_example/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require'
    from /Users/User/.rvm/gems/ruby-2.2.3@backbone_example/gems/spring-1.3.6/lib/spring/application.rb:92:in `preload'
    from /Users/User/.rvm/gems/ruby-2.2.3@backbone_example/gems/spring-1.3.6/lib/spring/application.rb:143:in `serve'
    from /Users/User/.rvm/gems/ruby-2.2.3@backbone_example/gems/spring-1.3.6/lib/spring/application.rb:131:in `block in run'
    from /Users/User/.rvm/gems/ruby-2.2.3@backbone_example/gems/spring-1.3.6/lib/spring/application.rb:125:in `loop'
    from /Users/User/.rvm/gems/ruby-2.2.3@backbone_example/gems/spring-1.3.6/lib/spring/application.rb:125:in `run'
    from /Users/User/.rvm/gems/ruby-2.2.3@backbone_example/gems/spring-1.3.6/lib/spring/application/boot.rb:18:in `<top (required)>'
    from /Users/User/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/User/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from -e:1:in `<main>'

@cymen
Copy link
Member

cymen commented Feb 17, 2016

Problem is here:

rails/sprockets-rails#223

Looking into a bit more.

@cymen
Copy link
Member

cymen commented Feb 17, 2016

Hrm, not quite the problem but in the same area. Looks like autoprefixer ran into this. But their change is how we are configuring so it's some issue in our dependencies.

ai/autoprefixer-rails#52

@AndyObtiva
Copy link

I was able to fix by updating "lib/browserify-rails/railtie.rb:33" from:

app.assets.register_postprocessor "application/javascript", BrowserifyRails::BrowserifyProcessor

to:

Sprockets.register_postprocessor "application/javascript", BrowserifyRails::BrowserifyProcessor

The new versions of sprockets components that came with Rails 4.2.5.1 are:
sprockets - 3.5.2
sprockets-rails - 3.0.1

@cymen
Copy link
Member

cymen commented Feb 17, 2016

Just upgrading to sprockets 3.5.2 seems to be fixing it for me. I'm just about to release a version w/ that but looks like 3.5.2 requires activesupport version that requires I upgrade ruby so going to take a minute.

@AndyObtiva
Copy link

Thanks a lot. You rock!

@cymen
Copy link
Member

cymen commented Feb 17, 2016

@AndyObtiva But that lower line is only run if config doesn't respond to assets (which it does with newer versions of things) so I think you have the same fix as me (the earlier line actually runs). So just upgrading sprockets should be 👍.

@cymen
Copy link
Member

cymen commented Feb 17, 2016

@AndyObtiva Forgot to say, thanks. It is hard keeping track of these changes. Really helpful to have confirmation on right path :).

@cymen
Copy link
Member

cymen commented Feb 17, 2016

@AndyObtiva @dbackeus I bumped the dependency in the gemspec on sprockets up to 3.5.2 and release browserify-rails 3.0.0. Would you try the new version and confirm it works correctly for you?

Thanks!

(and reopening -- I didn't mean for this to get closed until confirmed fixed)

@cymen cymen reopened this Feb 17, 2016
@AndyObtiva
Copy link

Worked for me. 👍

@dbackeus
Copy link
Author

Still have the very same error... same line same file but now on version 3.0.0... sprockets-rails is at 3.0.2 and sprockets at 3.5.2.

@cymen
Copy link
Member

cymen commented Feb 25, 2016

@dbackeus What version of Rails are you using? I tested with Rails 4.2.5.1 and it worked for me with browserify-rails 3.0.0. I'm checking Rails version with rails -v.

@cymen
Copy link
Member

cymen commented Feb 26, 2016

@dbackeus The other thing that would help is if you, with your version of Rails, can make a new project and pull in browserify-rails and add a simple module that demonstrates the failure. I'm happy to take a closer look.

I suspect the issue comes down to some of these gems following Rails releases and we'd need more stringent versioning to be compatible with all versions of Rails. I think supporting current is enough but I'm open to ideas (and solutions).

@cymen
Copy link
Member

cymen commented Mar 3, 2016

Closing due to lack of response. If anyone else has this issue, please reopen after pushing up an example failing Rails app to github.

@cymen cymen closed this as completed Mar 3, 2016
@kolomeetz
Copy link

I have the same problem with browserify-rails 1.0.2, sprockets 3.7.0 and rails 4.2.7.1.

Here is the clean project with this bug: https://github.com/kolomeetz/browserify-sprockets

@cymen
Copy link
Member

cymen commented Oct 14, 2016

@kolomeetz browserify-rails 3+ should be compatible. I'd recommend trying the latest which is version 3.1.0. Is there a reason you're using such an old version (1.02)?

@cymen
Copy link
Member

cymen commented Oct 15, 2016

@kolomeetz whoops, I meant 3.2.0 not 3.1.0. Anyway, does that fix it?

@kolomeetz
Copy link

Yes, my bad. 3.2.0 works perfectly! I'm sorry for having disturbed you.

@valentin-krasontovitsch

Got the same problem trying to run some specs in a rails eninge gem.

Using sprockets 3.6.0, sprockets-rails 3.0.4, browserify-rails 3.3.0, and no rails, since it's an engine.

#135 (comment) fixed it for me (changing line 35 in railtie.rb, the case of config doesn't respond to :assets).

If you really really want me to publish an easily reproducible example, I can try tomorrow.

@cymen
Copy link
Member

cymen commented Nov 24, 2016

@valentin-krasontovitsch So you still have the breakage with browserify-rails current (3.4.0)? If so, let's figure out a fix. I'm worried if I just make the change in comment 135, it'll break on earlier versions of Sprockets. The gemspec for browserify-rails has:

spec.add_runtime_dependency "sprockets", ">= 3.5.2"

So I'd want to test with Sprockets 3.5.2 and if it is broken, either figure out a work around or bump the dependency to 3.6.

@cymen cymen reopened this Nov 24, 2016
@cymen
Copy link
Member

cymen commented Nov 24, 2016

@valentin-krasontovitsch I decided to just go for it -- can you try browserify-rails 4.0.0.b? The .b is for beta. I upped the Sprockets dependency to >= 3.6.0 and changed it to use the code in comment 135. Let me know if it is good for you!

If so, I'll release 4.0.0. I figured might as well bump the major version just in case some people are stuck on Sprockets < 3.6.0.

@valentin-krasontovitsch

Sorry, was out for the day yesterday.
That totally fixed it for me, thanks a lot!

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.

5 participants