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

undefined method `bytesize' for nil:NilClass #50

Open
brumm opened this issue Mar 23, 2015 · 8 comments
Open

undefined method `bytesize' for nil:NilClass #50

brumm opened this issue Mar 23, 2015 · 8 comments

Comments

@brumm
Copy link

brumm commented Mar 23, 2015

Rack::Utils.bytesize blows up if the master stylesheet is empty.

NoMethodError - undefined method `bytesize' for nil:NilClass:
  rack (1.6.0) lib/rack/utils.rb:361:in `bytesize'
  sprockets (2.12.3) lib/sprockets/bundled_asset.rb:29:in `initialize'
  sprockets (2.12.3) lib/sprockets/base.rb:377:in `build_asset'
  sprockets (2.12.3) lib/sprockets/index.rb:94:in `block in build_asset'
  sprockets (2.12.3) lib/sprockets/caching.rb:58:in `cache_asset'
  sprockets (2.12.3) lib/sprockets/index.rb:93:in `build_asset'
  sprockets (2.12.3) lib/sprockets/base.rb:287:in `find_asset'
  sprockets (2.12.3) lib/sprockets/index.rb:61:in `find_asset'
  sprockets (2.12.3) lib/sprockets/environment.rb:75:in `find_asset'
  sprockets (2.12.3) lib/sprockets/base.rb:295:in `[]'
  sprockets-rails (2.2.4) lib/sprockets/rails/helper.rb:230:in `lookup_asset_for_path'
  sprockets-rails (2.2.4) lib/sprockets/rails/helper.rb:190:in `check_errors_for'
  sprockets-rails (2.2.4) lib/sprockets/rails/helper.rb:89:in `asset_path'
  actionview (4.2.0) lib/action_view/helpers/asset_url_helper.rb:267:in `stylesheet_path'
  actionview (4.2.0) lib/action_view/helpers/asset_tag_helper.rb:100:in `block in stylesheet_link_tag'
  actionview (4.2.0) lib/action_view/helpers/asset_tag_helper.rb:96:in `stylesheet_link_tag'
  sprockets-rails (2.2.4) lib/sprockets/rails/helper.rb:170:in `stylesheet_link_tag'
  css_splitter (0.4.1) app/helpers/css_splitter/application_helper.rb:18:in `block in split_stylesheet_link_tag'
  css_splitter (0.4.1) app/helpers/css_splitter/application_helper.rb:7:in `split_stylesheet_link_tag
@jhilden
Copy link
Contributor

jhilden commented Mar 26, 2015

We should try to create a failing test for this issue

@Umofomia
Copy link
Contributor

While css_splitter does appear in the backtrace, the error appears to have resulted from its split_stylesheet_link_tag method calling the Sprockets-defined stylesheet_link_tag method on the empty stylesheet.

Does the error also occur if you directly call Sprockets' stylesheet_link_tag with your empty stylesheet? If so, then it's probably more likely that the bug is with Sprockets than with css_splitter.

@liorbrauer
Copy link

I'm getting the same error (NoMethodError: undefined method 'bytesize' for nil:NilClass).

@Umofomia, I checked and called stylesheet_link_tag on an empty stylesheet, and it did not return any errors, so presumably the issue is with css_splitter.

@jhilden
Copy link
Contributor

jhilden commented Aug 31, 2015

@liorbrauer can you provide any additional information?

@liorbrauer
Copy link

@jhilden Hi, I continued fiddling with it and got it working. The issue for me was that I needed to provide the path to the too_big_stylesheet when writing the *= require 'too_big_stylesheet' (it is placed inside a folder under stylesheets). I wrongly assumed that since the too_big_stylesheet_split2.css was on the same folder as the too_big_stylesheet there was no need for the path.

jhilden added a commit that referenced this issue Sep 1, 2015
@jhilden
Copy link
Contributor

jhilden commented Sep 1, 2015

I'm glad you were able to fix it @liorbrauer

I tried to reproce the issue you were having in this branch (https://github.com/zweilove/css_splitter/compare/reproduce-issue-50) to see if we could give a better error message in this case.
But when I ran RAILS_ENV=production bundle exec rake assets:precompile inside test/dummy I got this error message instead of what you described:

Sprockets::FileNotFound: couldn't find file 'too_big_stylesheet.css' with type 'text/css'
/css_splitter/test/dummy/app/assets/stylesheets/folder/too_big_stylesheet_split2.css:2

Any tips for me what could be different? What are your rails/sprockets versions?

@liorbrauer
Copy link

@jhilden Thanks, this gem has really helped us!

Regarding your question: I looked at the branch you linked. That's not what I did - I added the folder/ bit inside the too_big_stylesheet_split2.css file, like so:

/*
 *= require 'folder/too_big_stylesheet'
 */

Hope that it is more clear?

@liorbrauer
Copy link

Also: Using rails 3.2.22 and sprockets 2.2.3

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

No branches or pull requests

4 participants