Skip to content

Jekyll Sass Compile Error Fix

DodaTech Updated 2026-06-24 1 min read

In this tutorial, you'll learn about Jekyll Sass Compile Error Fix. We cover key concepts, practical examples, and best practices.

The Problem

Error: Invalid CSS after "...import 'variables": expected selector or at-rule, was '.primary-color'
   on line 5 of sass/main.scss

Jekyll's built-in Sass processor requires the correct syntax for imports and variable usage.

Wrong

// main.scss
@import 'variables';
body {
  color: $primary-color;
}

With no _variables.scss file present, Jekyll throws Error: File to import not found or unreadable: variables.

Create _sass/_variables.scss:

$primary-color: #007bff;

In assets/css/main.scss:

---
---
@import 'variables';
body {
  color: $primary-color;
}

Output: compiled CSS with the primary color applied.

The frontmatter (---) tells Jekyll to process the file through its Sass converter.

Prevention

  • Prefix SCSS partials with underscore (e.g. _variables.scss)
  • Place partials in the _sass/ directory
  • Add --- frontmatter to files that need Sass processing

Common Mistakes with sass compile

  1. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  2. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  3. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks

These mistakes appear frequently in real-world JEKYLL code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does Jekyll not compile my SCSS files?

SCSS files must have frontmatter (---) and be placed in a location that Jekyll processes. Use assets/css/main.scss with frontmatter to trigger Sass compilation.

What is the difference between _sass/ and assets/css/?

Use _sass/ for partial SCSS files (imported by other files). Use assets/css/ for files that generate CSS output. Only files in assets/css/ with frontmatter create compiled stylesheets.

How do I use the @import directive in Jekyll SCSS?

Place partials in _sass/ prefixed with underscore (e.g. _reset.scss). Import them without the underscore and extension: @import 'reset'.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro