【问题标题】:I can't use @use in sass file in Create React App + node-sass setup我不能在 Create React App + node-sass setup 的 sass 文件中使用 @use
【发布时间】:2020-08-17 23:39:17
【问题描述】:

在我的src/styles/variables.scss 文件中,我定义了$primary-color: #171b42;

我想在我的src/components/LandingPage/LandingPage.module.scss 文件中使用这个变量。

在这个文件中,我有:

@use "../../styles/variables.scss" as v;

$color: v.$primary-color;

.heading {
  color: $color;
}

我收到此错误:

SassError: Invalid CSS after "$color: v": expected expression (e.g. 1px, bold), was ".$primary-color;"

我做错了什么?我安装了node-sass

【问题讨论】:

    标签: reactjs sass node-sass


    【解决方案1】:

    我刚刚安装了 'sass' 而不是 'node-sass' 并且它起作用了。

    【讨论】:

    • @NULLpointer 只需执行 'npm i -D sass' 。 node-sass 使用 libsass,sass 使用 dartsass
    【解决方案2】:

    我刚刚遇到了同样的问题。如果您密切关注Sass documentation,它会说(截至 2020 年 5 月 16 日):

    目前只有 Dart Sass 支持 @use。其他实现的用户必须改用@import 规则。

    【讨论】:

    • 对于任何在文档中搜索它的人(如我):(当前)在页面顶部的“兼容性”下,有一个折叠的隐藏部分可通过三角形图标访问。跨度>
    猜你喜欢
    • 2021-01-04
    • 2020-09-20
    • 1970-01-01
    • 2018-09-16
    • 1970-01-01
    • 2019-04-07
    • 2019-06-27
    • 1970-01-01
    • 2019-10-14
    相关资源
    最近更新 更多