Sprockets not parsing JS/CSS rules with Ruby 2.0 #352

luislavena opened this Issue Sep 3, 2012 · 4 comments


None yet
2 participants


While testing Ruby 2.0 with a new (and clean) Rails application, I found that sprockets no longer process CSS or JS rules like require or require_tree

  • To recreate this issue, install Ruby 2.0 (revision 36890 was tested)
  • Install rails gem install rails
  • Create a new empty Rails application with defaults (rails new foobar)
  • Create a controller (rails g controller welcome index)
  • Start the server (rails s) and visit the newly created action.

When inspecting source, will notice that only application.js is listed as source and neither jquery or jquery_ujs

After cloning sprockets source and running tests, noticed the following Regexp warnings:

$ rake test
Run options: 

# Running tests:

[  1/417] BundledAssetTest#test "__FILE__ is properly set in templates"/Users/luis/code/sstephenson/sprockets/lib/sprockets/directive_processor.rb:127: warning: character class has duplicated range: /
      ^ [\W]* = \s* (\w+.*?) (\*\/)? $
[ 96/417] EncodingTest#test "read ASCII + UTF-8 concatation asset"/Users/luis/code/sstephenson/sprockets/lib/sprockets/directive_processor.rb:127: warning: character class has duplicated range: /
      ^ [\W]* = \s* (\w+.*?) (\*\/)? $
Finished tests in 20.283325s, 20.5588 tests/s, 52.8513 assertions/s.                                                    
417 tests, 1072 assertions, 0 failures, 0 errors, 0 skips

ruby -v: ruby 2.0.0dev (2012-09-03 trunk 36890) [x86_64-darwin10.8.0]

At first, I looked at Sprockets::DirectiveProcessor to verify if directives gets processed properly, and it does:

$ irb -Ilib
irb(main):001:0> require "sprockets"
=> true
irb(main):002:0> dp = Sprockets::DirectiveProcessor.new(File.expand_path("~/sandbox/foobar/app/assets/javascripts/application.js"))
=> #<Sprockets::DirectiveProcessor:0x000001011a4af8 ...>
irb(main):003:0> dp.directives
=> [[13, "require", "jquery"], [14, "require", "jquery_ujs"], [15, "require_tree", "."]]

Which puts to the ground my theory that Regexp could be the cause issue.

Next I thought uglifier could be associated, as previously had issues with it, so disabled it and also disable it from production.rb (config.assets.compress = false) but with same result: generated application.js do not include jquery or any of the required directives.

Contrary to what is stated in #351, cleaning assets and precompile them again doesn't work and neither the removal of the compiled interpreter.

Perhaps @tenderlove knows better about this, as he has more experience when using Ruby 2.0 than myself.

Thank you! ❤️ ❤️ ❤️

A bit more (dunno if this helps or not) but exactly same application with Ruby 1.9.3-p194 works perfectly.

Sorry that I'm unable to provide better debug information to figure out the culprit, but will love to help.

Thank you.


josh commented Sep 4, 2012

Thanks for the detailed write up. I've created a branch to start better support for Ruby 2.0.


josh closed this Sep 4, 2012

Thank you @josh

I think the issue with Ruby 2.0 is also associated to Rails 3.2.8 (actionpack gem) which is locked down to an earlier version of sprockets:


sprockets ~> 2.1.3

And due that requirement, there is no way to take advantage of any of the fixes to newer version of sprockets.

(of course, not without running really bleeding edge Rails 4, 😱)

Thanks again for taking care of the warning.


josh commented Sep 4, 2012

@luislavena thanks for your help. I'll be keeping the ruby-head builds green from here forward.

@grig grig added a commit to overmobile/rails that referenced this issue Apr 1, 2014

@grig grig Relax dependecy requirements for 'sprockets' gem
Attempt to import a fix to sprockets issue #352 [1] to a local codebase.

[1] sstephenson/sprockets#352

ojab referenced this issue in janv/rest_in_place Jul 1, 2014


Fix testapp with ruby-2.0, handle HTTP 204 No content #58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment