简体   繁体   English

React JS 中的 Sass 构建失败

[英]Sass build failing in React JS

I have following Sass script:我有以下 Sass 脚本:

@import "../../../../global_css/variables/variables";
.heading .sectionAbout {
    padding: $padding-top-viewport 0;
    margin-top: calc(-1 * (#{top-viewport-height} - #{clip-background-height}));
    background: $color-grey-light-1;
}

When I try to run the build file in react using yarn build ( "build": "react-scripts build", ), I get an error:当我尝试使用yarn build ( "build": "react-scripts build", ) 在 react 中运行构建文件时,出现错误:

yarn run v1.22.5
$ react-scripts build
Creating an optimized production build...
Failed to compile.

Lexical error on line 1: Unrecognized text.
  Erroneous area:
1: -1 * (top-viewport-height - clip-background-height)
^........^
CompileError: Begins at CSS selector undefined

My node-sass version is "node-sass": "4.14.1" .我的node-sass版本是"node-sass": "4.14.1" How do I get rid of this irritating error to proceed with my build?我如何摆脱这个恼人的错误以继续我的构建?

You need to include $ before your variable.您需要在变量之前包含 $ 。 I believe this is missed out for the two variables used inside calc function我相信 calc 函数中使用的两个变量会忽略这一点

Try尝试

@import "../../../../global_css/variables/variables";
.heading .sectionAbout {
    padding: $padding-top-viewport 0;
    margin-top: calc(-1 * (#{$top-viewport-height} - #{$clip-background-height}));
    background: $color-grey-light-1;
}

Ref:- https://sass-lang.com/documentation/interpolation参考:- https://sass-lang.com/documentation/interpolation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM