jekyll: Invalid US-ASCII character "\xE2"

There’s quite a few pages on the Internet talking about this problem with Ruby but none of the solutions seem to work with Jekyll. Ultimately, I’m trying to build a Jekyll site in a Docker container and I’ve tried setting @charset as well as all the locale ENV variables. is there something I can set in _config.yml to solve this?

Configuration file: /www/_config.yml
            Source: /www
       Destination: /www/_site
 Incremental build: enabled
      Generating...
  Conversion error: Jekyll::Converters::Scss encountered an error while converting 'assets/css/styles.scss':
                    Invalid US-ASCII character "\xE2" on line 3
/usr/local/bundle/gems/jekyll-sass-converter-1.3.0/lib/jekyll/converters/scss.rb:97:in `rescue in convert': Invalid US-ASCII character "\xE2" on line 3 (Jekyll::Converters::Scss::SyntaxError)
    from /usr/local/bundle/gems/jekyll-sass-converter-1.3.0/lib/jekyll/converters/scss.rb:95:in `convert'
    from /usr/local/bundle/bundler/gems/jekyll-43a28aed967b/lib/jekyll/convertible.rb:67:in `block in transform'
    from /usr/local/bundle/bundler/gems/jekyll-43a28aed967b/lib/jekyll/convertible.rb:65:in `each'
    from /usr/local/bundle/bundler/gems/jekyll-43a28aed967b/lib/jekyll/convertible.rb:65:in `reduce'
    from /usr/local/bundle/bundler/gems/jekyll-43a28aed967b/lib/jekyll/convertible.rb:65:in `transform'
    from /usr/local/bundle/bundler/gems/jekyll-43a28aed967b/lib/jekyll/convertible.rb:249:in `do_layout'
    from /usr/local/bundle/bundler/gems/jekyll-43a28aed967b/lib/jekyll/page.rb:122:in `render'
    from /usr/local/bundle/bundler/gems/jekyll-43a28aed967b/lib/jekyll/site.rb:302:in `block in render'
    from /usr/local/bundle/bundler/gems/jekyll-43a28aed967b/lib/jekyll/site.rb:301:in `each'
    from /usr/local/bundle/bundler/gems/jekyll-43a28aed967b/lib/jekyll/site.rb:301:in `render'
    from /usr/local/bundle/bundler/gems/jekyll-43a28aed967b/lib/jekyll/site.rb:55:in `process'
    from /usr/local/bundle/bundler/gems/jekyll-43a28aed967b/lib/jekyll/command.rb:28:in `process_site'
    from /usr/local/bundle/bundler/gems/jekyll-43a28aed967b/lib/jekyll/commands/build.rb:58:in `build'
    from /usr/local/bundle/bundler/gems/jekyll-43a28aed967b/lib/jekyll/commands/build.rb:34:in `process'
    from /usr/local/bundle/bundler/gems/jekyll-43a28aed967b/lib/jekyll/commands/build.rb:18:in `block (2 levels) in init_with_program'
    from /usr/local/bundle/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `call'
    from /usr/local/bundle/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `block in execute'
    from /usr/local/bundle/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `each'
    from /usr/local/bundle/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `execute'
    from /usr/local/bundle/gems/mercenary-0.3.5/lib/mercenary/program.rb:42:in `go'
    from /usr/local/bundle/gems/mercenary-0.3.5/lib/mercenary.rb:19:in `program'
    from /usr/local/bundle/bundler/gems/jekyll-43a28aed967b/bin/jekyll:20:in `<top (required)>'
    from /usr/local/bundle/bin/jekyll:16:in `load'
    from /usr/local/bundle/bin/jekyll:16:in `<main>'
rake aborted!
Command failed with status (1): [bundle exec jekyll build --trace...]
/www/Rakefile:295:in `jekyll'
/www/Rakefile:97:in `block in <top (required)>'
Tasks: TOP => build
(See full trace by running task with --trace)

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 31 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for the reply @parkr but after searching, I manage to fix it and I’m sharing my solution. I found out that the docker container is using a different charset or locale so you have to set it in you docker file.

I manage to fix mine by adding this on my Dockerfile. No need to upgrade to sass converter 1.4.0.

# Install program to configure locales
RUN apt-get install -y locales
RUN dpkg-reconfigure locales && \
  locale-gen C.UTF-8 && \
  /usr/sbin/update-locale LANG=C.UTF-8

# Install needed default locale for Makefly
RUN echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen && \
  locale-gen

# Set default locale for the environment
ENV LC_ALL C.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8

Hope this helps everyone!

My jekyll build is being done by AWS CodeBuild, and I found I needed to add these lines to the buildspec.yml file:

  pre_build:
    commands:
      - export LC_ALL="C.UTF-8"
      - export LANG="en_US.UTF-8"
      - export LANGUAGE="en_US.UTF-8"

I also ran into this problem, and found this thread very helpful but it didn’t cover my case. Hopefully this helps the next person.

For me, setting LANG=en_US.UTF-8 didn’t work because the locale hadn’t been generated on my system and it was falling back to LANG=C which caused the error. Additionally, the problematic character I had was an en-dash (\xe2\x80\x93) not actually â (\xe2). The fix was to generate a UTF-8 locale and set it. Instructions tested on Arch Linux.

  1. Check if locale exists before you try to set it: locale -a
  2. If not, generate locale: Uncomment locale name in /etc/locale.gen and run sudo locale-gen
  3. Set locale for the system: Edit /etc/locale.conf and log in again for it to take effect
  4. Or set locale for the terminal
    • bash: export LANG=en_US.UTF-8
    • fish: set -xg LANG en_US.UTF-8

For the record, I found this great one-liner for finding non-ASCII characters:

# Linux
grep --color='auto' -P -n "[\x80-\xFF]" file.xml

# Mac OS X after brew install pcre
pcregrep --color='auto' -n "[\x80-\xFF]" file.xml

If anyone is getting this on GitLab, add the list on the above ^ https://github.com/jekyll/jekyll/issues/4268#issuecomment-357095209

just put this in a before_script: before everything else

Just for the future reference:

I originally turned off Set locale environment variables on startup in my OSX Terminal preference due to other reasons. The error is gone if I check this checkbox.

I’m also having this issue. No problem if hosted via GitHub pages, but when I use docker on my own laptop or server, it has this issue.

The problem is the

---
---

above the scss file. If you remove this, there would be no error but the scss will not be converted. Still don’t know how to fix this.

For Jekyll on Gitlab, alternative to @IotaSpencer’s solution is adding them in variables, like:

variables:
  LC_ALL: "C.UTF-8"
  LANG: "en_US.UTF-8"
  LANGUAGE: "en_US.UTF-8"

I get this problem when building a Jekyll site with wercker and there’s Unicode in the SASS. Removing the UTF-8 characters or using @AngeloAballe’s solution works.

I ran into this issue as well while trying to build my project over at GitLab. What was causing the issue was this bit of code:

...
a::before{
  content:'“';
}
a::after{
  content:'”';
}
...

The and were the culprits. Changing them to be the hex value fixed the issue.

...
a::before{
  content:'\201C';
}
a::after{
  content:'\201D';
}
...

@AngeloAballe The YAML front matter (two lines of ---) are not the problem – they merely tell Jekyll to convert the SCSS into CSS. Have you tried outside of Docker? See Dalan’s comment about finding these characters:

# Linux
grep --color='auto' -P -n "[\x80-\xFF]" file.xml

# Mac OS X after brew install pcre
pcregrep --color='auto' -n "[\x80-\xFF]" file.xml

Happened again with the _config.yml change. I ack’d through my repo and couldn’t find any of those and don’t see why I would have any non-English characters in the imports. Also, it says it’s occurring here in the styles.scss file:

Conversion error: Jekyll::Converters::Scss encountered an error while converting 'assets/css/styles.scss':
                    Invalid US-ASCII character "\xE2" on line 3
/usr/local/bundle/gems/jekyll-sass-converter-1.3.0/lib/jekyll/converters/scss.rb:97:in `rescue in convert': Invalid US-ASCII character "\xE2" on line 3 (Jekyll::Converters::Scss::SyntaxError)

assets/css/styles.scss

---
---
@charset "utf-8";

// Bourbon, Neat, Bitters, Base styles
@import "normalize";
@import "bourbon";
@import "neat";
@import "base/base";