Getting Undefined variable error when compiling SCSS using node-sass

◇◆丶佛笑我妖孽 提交于 2020-07-08 07:05:01

问题


package.json

"scripts": {
  "compile:sass": "node-sass sass/main.scss css/style.css -w"
}

main.scss

@import "abstracts/variables";
@import "base/typography";  

_variables.scss

$color-light-grey: #777;
$color-white: #fff;   

_typography.scss

body {
  color: $color-light-grey;
}
.heading-primary {
  color: $color-white;
}

Now my issue is when I'm trying to compile with npm run compile:sass it throws the following error:

"message": "Undefined variable: \"$color-light-grey\"."


回答1:


Looks like there are two errors in your code above:

  • You import "abstracts/variables" but, at least in the text, the file name seems to be _variables.scss (missing an "s")
  • You should import "abstracts/variables" before everything else.

Like that:

@import "abstracts/variables";
@import "base/typography";



回答2:


convert all file names with beginning "_"
example:
typography.scss >> to >> _typography.scss



来源:https://stackoverflow.com/questions/47506906/getting-undefined-variable-error-when-compiling-scss-using-node-sass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!