Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SASS compile error: undefined variable [duplicate]

I'm using Koala to compile SASS and getting the following error:

C:.....\HTML\scss\style.scss
Error: Undefined variable: "$font-primary".
        on line 2 of C:...../HTML/scss/_base.scss
        from line 7 of C:.....\HTML\scss\style.scss
  Use --trace for backtrace.

EDIT - For reference, here are the code snippets I'm currently using:

style.scss

// Vendor
@import url(http://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
@import 'vendor/foundation';
@import 'vendor/normalize';

// Base
@import 'base';
@import 'mixins';
@import 'variables';

// Layout
@import 'header';
@import 'footer';

_variables.scss

// Colours
$black:         #2e2e2e;
$cream:         #fcfbf5;
$green:         #b2ca9d;
$green-dark:    #4d6638;
$grey-light:    #808080;
$grey:          #4f4f4f;
$pink-light:    #f8d8d8;
$pink:          #f0acac;
$pink-dark:     #835151;
$white:         #ffffff;

// Fonts
$font-primary:  'Droid Serif', serif;

_base.scss

body {
    font-family: $font-primary;
    line-height: 1.5;
    color: $black;
}

h1, h2, h3, h4, h5, h6 {
    font-family: $font-primary;
    text-transform: uppercase;
    letter-spacing: 0.1rem;
}

h1, h2 {
    font-size: 2.25rem;
}

.image-replace {
    width: 100%;
    height: 0;
    display: inline-block;
    font: 0/0 a;
    text-shadow: none;
    color: transparent;
    border: 0;
    background-color: transparent;
}

My issue is that the variable $font-primary most definitely is being defined in _variables.scss (which is also definitely being imported into my main style.scss) so I'm really confused about how/why the error is being generated.

I have checked the encoding of all my files and they are using UTF-8 without BOM, which was a suggested fix in other similar questions.

Incidentally, this is the first variable referenced in _base.scss. If I remove the reference, the error remains but moves on to the next variable reference in the file.

Thanks in advance!

like image 990
Jack Avatar asked Mar 22 '15 11:03

Jack


1 Answers

I think you just only have to re-order the includes, calling the _variables.scss before you call _base.scss:

// Base 
@import 'variables';
@import 'base'; 
@import 'mixins'; 
like image 122
dnvtrn Avatar answered Sep 27 '22 22:09

dnvtrn