Ruby 1.9 和 Sass 编码问题。 (从 ASCII-8BIT 到 UTF-8)
我最近升级到 Ruby 1.9,无法再使用 Sass 编译任何内容。
我见过的解决方案指出,如果我将其放在
@charset "utf-8";
.sccs 文件的顶部,它将修复它。但是我仍然收到错误。这是完整的回溯,
我还尝试从 CSS 文件中删除所有非 ASCII 字符、创建一个新字符等。它只是无法编译。有什么建议吗?
回溯:
Sass 正在观察变化。按 Ctrl-C 停止。
/home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:496:in `encode': 不支持转码(从 ASCII-8BIT 到 UTF-8)(参数错误)
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:496:in
_enc' 来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:515:in
rescue in block (1 level) in '来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:508:in `block (1 level) in '
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:472:in `yield'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:472:in `default'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:472:in `check_sass_encoding 中的块'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:471:in `each'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:471:in `find'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:471:in `check_sass_encoding'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/engine.rb:349:in `check_encoding!'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/engine.rb:316:in `_to_tree'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/engine.rb:291:in `_render'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/engine.rb:238:in `render'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/plugin/compiler.rb:319:in `update_stylesheet'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/plugin/compiler.rb:169:in `update_stylesheets 中的块'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/plugin/compiler.rb:167:in `each'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/plugin/compiler.rb:167:in `update_stylesheets'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/plugin/compiler.rb:214:in `watch'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/plugin.rb:111:in `method_missing'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/exec.rb:408:in `watch_or_update'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/exec.rb:294:in `process_result'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/exec.rb:41:in `parse'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/exec.rb:21:in `parse!'
来自 /home/webdev/.gem/repository/gems/sass-3.1.1/bin/sass:8:in `'
来自 /home/webdev/.gem/repository/bin/sass:19:in `load'
来自 /home/webdev/.gem/repository/bin/sass:19:in `'
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'
rescue in block (1 levels) in '
from /home/webdev/.gem/repository/gems/sass-3.1.1/lib/sass/util.rb:515:infrom /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 `'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
要完成 @nex3 答案,您可以
打开
config.rb
文件并添加:To complete @nex3 answer you can
Open the
config.rb
file and add:看起来您的 Ruby 环境不知何故被设置为将 Sass 源代码加载为
ASCII-8BIT
(又名BINARY
)。这可能是因为您将-Kn
标志传递给 Ruby 进程,或者将Encoding.default_external
设置为Encoding::BINARY
某处在加载 Sass 之前在您的代码中。撤消此操作,Sass 应该可以工作。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 settingEncoding.default_external
toEncoding::BINARY
somewhere in your code before Sass is loaded. Undo this, and Sass should work.我不太清楚问题的核心,但 Ruby 1.9.0(该 Ubuntu 盒子上的 apt 可用版本)和编码似乎存在一些问题。
为了解决这个问题,我使用了 https://rvm.io 这是一个从 Git 下载和编译 Ruby 的助手,给出了我最新版本。运行后,sass 编译良好,一切都很好。
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.
这发生在我身上,解决方案并不明显:Jet Brains 的 Elena Pogorelova 在这篇文章中解释说,文件路径中的非 ASCII 字符可能会破坏 SASS,就像我的情况一样。
users/xxxx/projects/chilediseño/cms/scss
(ñ)我只需删除上面名称中的 (ñ) 即可,一切正常。
This happened to me and the solution was not apparent: Elena Pogorelova of Jet Brains explained in this post that non-ASCII characters in your files route may break SASS, as was in my case.
users/xxxx/projects/chilediseño/cms/scss
(ñ)I just had to eliminate the (ñ) in the name above and everything worked.
这可能是显而易见的,但您确定您的 Sass 文件是 UTF-8 编码的吗?任何像样的文本编辑器都可以让您转换编码。
This is probably obvious, but are you sure your Sass file is UTF-8 encoded? Any decent text editor will let you convert encodings.