Windows環境下でgrunt-contrib-sassでコンパイル時に以下のエラーが表示された時の対処法
Running "sass:dist" (sass) task
Error: Invalid Windows-31J character "\xE6"
on line 5 of xxx/xxx/yyy.scss
Use --trace for backtrace.
Warning: Exited with error code 65 Use --force to continue.
原因
コンパイル対象のSCSSに日本語(漢字)が含まれていることでエラーが発生しています
例えば以下のようにfont-familyに日本語を含む場合
yyy.scss
body {
font-family: Verdana, "游ゴシック", YuGothic, "メイリオ", Meiryo, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", "MS Pゴシック", sans-serif;
}
対策方法
scssファイルの先頭行に@charset "utf-8";
を追加してあげればOK
yyy.scss
@charset "utf-8";
body {
font-family: Verdana, "游ゴシック", YuGothic, "メイリオ", Meiryo, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", "MS Pゴシック", sans-serif;
}
以上