sass: Undefined variable error but variable is indeed defined
//_variable.scss
$blue-base: #66ccff;
$blue-dark: darken($blue-base, 10%);
$blue: $blue-base;
$blue-light: lighten($blue-base, 10%);
$blue-lighter: lighten($blue-base, 20%);
$blue-lightest: lighten($blue-base, 25%);
$link-color: $blue-dark;
$link-some-active-color: $blue;
// _global.scss
a {
color: $link-color;
text-decoration: none;
&:hover, &:active, &:focus {
color: $link-some-active-color;
}
}
Error:
events.js:141
throw er; // Unhandled 'error' event
^
Error: src/sass/_global.scss
Error: Undefined variable: "$link-some-active-color".
on line 20 of src/sass/_global.scss
>> color: $link-some-active-color;
---------------^
I am using Gulp.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 19 (1 by maintainers)
@manix I faced the same issue with Sass, in my case the error was because I included the variables file after the other file where I used them, you could try doing this, reorder files import, make the variables file at the top.
@guoyunhe can you elaborate?
Found the reason, I import in a wrong way.
I made the mistake of declaring variables inside :root. As in; :root { $primary-color: #fff; } So when I referenced this variable, it gave me that error. FIxing it is as easy as removing :root and the curly braces…
how to import file
You can also name all your files with an underscore upfront (e.g.
_color.scss
,_font.scss
,_button.scss
, etc.) and import them in one singlestyle.scss
:This technique is called partials and will merge all your styles in one single CSS output so ordering gets sorted out by SCSS. Note that the filenames start with an underscore but the imports don’t.
@majidzeno wow, thank you so much. I also stuck at that error