Invalid US-ASCII character Error when compiling Jekyll

February 13, 2019

When compiling TMB for the first time on our production server we ran into a strange error we’d never seen before:

Conversion error: Jekyll::Converters::Scss encountered an error while
converting 'assets/css/main.scss':
Invalid US-ASCII character "\xE2" on line 12

Examining our main sass file didn’t lead us anywhere either:

---
# Only the main Sass file needs front matter (the dashes are enough)
---
@charset "UTF-8";
// Our variables

// Import partials from `sass_dir` (defaults to `_sass`)
@import
        "normalize",
        "skeleton",
        "themountainborn";

The charset was properly set in the sass file, grepping for invalid ASCII characters revealed nothing, and systematically stepping through and deleting portions of the file and re-compiling revealed that stripping the dashes in the YAML frontmatter would remove the error1, but also prevented Jekyll from properly compiling the sass file into css (and thus breaking the site).

There are several threads out there on this issue but none of the solutions listed worked for us.

It turns out the solution was somewhat simpler (and totally unrelated to Jekyll/Sass) - we hadn’t set the locale properly on our server. Bash was even warning us every time we SSH’d in, but we’d just been glossing over it.

This can be done temporarily from the command line for each session:

export LANG=en_US.UTF-8

Or properly by setting the appropriate environment variables:

vi /etc/environment

then adding these lines:

LANG=en_US.utf-8
LC_ALL=en_US.utf-8

Problem solved.

  1. Not to mention that yes, the dashes were proper ASCII dashes and file encoding itself was set properly so that was equally confusing. 

Keep Reading

Related Posts

⤒ Back to top

Permalink