Jekyll Sass Compile Error Fix
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.
Right
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
- Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists - 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
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro