Ruby 1.9 and Sass encoding issues. (from ASCII-8BI

2019-04-29 04:18发布

问题:

I recently upgraded to Ruby 1.9 and I can no longer compile anything with Sass.

I've seen solutions that state if I place

 @charset "utf-8";

at the top of my .sccs file, it will fix it. However I'm still getting an error. Here's the full traceback

I've also tried removing any non-ascii characters from my CSS file, creating a new one, etc. It just won't compile. Any tips?

Traceback:

Sass is watching for changes. Press Ctrl-C to stop.

/home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:496:in `encode': transcoding not supported (from ASCII-8BIT to UTF-8) (ArgumentError)

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:496:in _enc' from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:515:inrescue in block (1 levels) in '

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:508:in `block (1 levels) in '

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:472:in `yield'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:472:in `default'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:472:in `block in check_sass_encoding'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:471:in `each'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:471:in `find'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:471:in `check_sass_encoding'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/engine.rb:349:in `check_encoding!'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/engine.rb:316:in `_to_tree'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/engine.rb:291:in `_render'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/engine.rb:238:in `render'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/plugin/compiler.rb:319:in `update_stylesheet'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/plugin/compiler.rb:169:in `block in update_stylesheets'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/plugin/compiler.rb:167:in `each'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/plugin/compiler.rb:167:in `update_stylesheets'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/plugin/compiler.rb:214:in `watch'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/plugin.rb:111:in `method_missing'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/exec.rb:408:in `watch_or_update'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/exec.rb:294:in `process_result'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/exec.rb:41:in `parse'

from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/exec.rb:21:in `parse!'

from /home/webdev/.gem/repository/gems/sass-3.1.1/bin/sass:8:in `'

from /home/webdev/.gem/repository/bin/sass:19:in `load'

from /home/webdev/.gem/repository/bin/sass:19:in `'

回答1:

To complete @nex3 answer you can

Open the config.rb file and add:

Encoding.default_external = "UTF-8"


回答2:

It looks like somehow your Ruby environment is set up to load the Sass source code as ASCII-8BIT, a.k.a. BINARY. This is probably because you're either passing the -Kn flag to the Ruby process, or setting Encoding.default_external to Encoding::BINARY somewhere in your code before Sass is loaded. Undo this, and Sass should work.



回答3:

I don't know exactly the core of the issue, but it seems there were some problems with Ruby 1.9.0 (the version available on apt for this Ubuntu box) and encoding.

To solve the issue, I used https://rvm.io which is a helper to download and compile Ruby from Git, giving me the latest version. After running this, sass compiles fine and everything is swell.



回答4:

This is probably obvious, but are you sure your Sass file is UTF-8 encoded? Any decent text editor will let you convert encodings.