使用node-sass编译SCSS时出现未定义的变量错误

时间:2017-11-27 08:49:17

标签: css npm sass node-sass

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;
}

现在我的问题是,当我尝试使用npm run compile:sass进行编译时,它会抛出以下错误:

  

" message":"未定义的变量:\" $ color-light-grey \"。"

2 个答案:

答案 0 :(得分:3)

将所有文件名以“ _”开头
示例:
typography.scss >>到>> _typography.scss

答案 1 :(得分:1)

您的代码中似乎有两个错误:

  • 您导入_variables.scss但是,至少在文本中,文件名似乎是"abstracts/variables"(缺少" s")
  • 您应该在其他所有内容之前导入@import "abstracts/variables"; @import "base/typography";

就像那样:

data have;
input  col1 $ p1 $ p2 $ p3 $ p4 $;
cards;
f1  x   .   .   .
f2  x   x   .   .
f3  .   x   .   x
f4  .   x   x   .
;
run;


data want;
retain col1 col2 values;
 set have;
 array p[4] $1. p1-p4;
 do i=1 to 4;
 values = p(i);
 col2 = compress("p"||i);
 output;
 end;
 keep col1 col2 values ;
run;