zweilove / css_splitter

Gem for splitting up stylesheets that go beyond the IE limit of 4095 selectors, for Rails 3.1+ apps using the Asset Pipeline.
MIT License
160 stars 47 forks source link

Sass::SyntaxError: @charset may only be used at the root of a document. #52

Closed kntmrkm closed 8 years ago

kntmrkm commented 9 years ago

Hello. I'm using this gem (ver 0.4.1) following env.

My development env is works well. but, when compile in production I get a error like this,

Sass::SyntaxError: @charset may only be used at the root of a document.

and, I have scss file following.

@media screen and (min-width: 768px) {
  //.container { max-width: 940px; }
}

@media screen and (max-width: 767px) {
  .variant {
    font-size: 15px;
  }
}

/* カスタム, iPhone Retinaディスプレイ */
//@media only screen and (max-width : 320px) {  }

Oddly enough. The error solve by several change.

case 1

@media screen and (min-width: 768px) {
  //.container { max-width: 940px; }
}

@media screen and (max-width: 767px) {

}

/* カスタム, iPhone Retinaディスプレイ */
//@media only screen and (max-width : 320px) {  }

It's works well.

case 2

@media screen and (min-width: 768px) {
  //.container { max-width: 940px; }
}

@media screen and (max-width: 767px) {
  .variant {
    font-size: 15px;
  }
}

It's works well too.

Additional above, following case works.

@media screen and (min-width: 768px) {
  .container { max-width: 940px; }
}

@media screen and (max-width: 767px) {
  .variant {
    font-size: 15px;
  }
}

I couldn't specify cause of this anymore.

Thanks.

kntmrkm commented 9 years ago

Additional info.

This case works too.

@media screen and (min-width: 768px) {
  //.container { max-width: 940px; }
}

@media screen and (max-width: 767px) {
  .variant {
    font-size: 15px;
  }
}

//@media only screen and (max-width : 320px) {  }

I guess that compile fails when CSS file includes elements which compilable target and CSS file includes Multibyte character ( In this case. It's Japanese.).

jhilden commented 9 years ago

Do you use any charset declaration in your Sass? There is some special handling for charset declarations in the splitter code, see: https://github.com/zweilove/css_splitter/blob/master/lib/css_splitter/splitter.rb

Also, a full stack trace of the error would be good, to see where the bug is happening.

Actually the ideal thing would be to have test case that reproduces the error.

kntmrkm commented 9 years ago

No, there is no charset declaration.

and full stack trace is

rake aborted!
Sass::SyntaxError: @charset may only be used at the root of a document.
(sass):1797
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/visitors/check_nesting.rb:13:in `visit'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/visitors/base.rb:52:in `block in visit_children'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/visitors/base.rb:52:in `map'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/visitors/base.rb:52:in `visit_children'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/visitors/check_nesting.rb:49:in `visit_children'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/visitors/base.rb:38:in `visit'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/visitors/check_nesting.rb:15:in `visit'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/visitors/base.rb:52:in `block in visit_children'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/visitors/base.rb:52:in `map'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/visitors/base.rb:52:in `visit_children'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/visitors/check_nesting.rb:49:in `visit_children'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/visitors/base.rb:36:in `block in visit'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/visitors/check_nesting.rb:57:in `visit_root'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/visitors/base.rb:36:in `visit'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/visitors/check_nesting.rb:15:in `visit'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/visitors/base.rb:24:in `visit'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/root_node.rb:35:in `css_tree'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/tree/root_node.rb:20:in `render'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sass-3.4.14/lib/sass/engine.rb:268:in `render'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/sass_compressor.rb:48:in `call'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/sass_compressor.rb:28:in `call'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:75:in `call_processor'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:56:in `call_processors'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/loader.rb:86:in `load_asset_by_uri'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/loader.rb:45:in `block in load'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/loader.rb:155:in `fetch_asset_from_dependency_cache'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/loader.rb:38:in `load'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/cached_environment.rb:47:in `yield'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/cached_environment.rb:47:in `load'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/base.rb:63:in `find_asset'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/base.rb:70:in `find_all_linked_assets'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:130:in `block in find'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:129:in `each'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:129:in `find'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:162:in `compile'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-rails-2.3.1/lib/sprockets/rails/task.rb:70:in `block (3 levels) in define'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-3.2.0/lib/rake/sprocketstask.rb:147:in `with_logger'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/sprockets-rails-2.3.1/lib/sprockets/rails/task.rb:69:in `block (2 levels) in define'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `load'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `block in load'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/kntmrkm/code/rails/reserven/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `load'
-e:1:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

Yes, you are right. It is best to have test case.

jhilden commented 8 years ago

Closing this issue due to inactivity.