css - 如何修复SCSS中的 undefined variable 错误?

标签 css sass compiler-errors undefined

我在编写SCSS时遇到了不确定变量错误。

  • 我的文件结构是合理的(我相信),因为它可以将其余文件编译为main.scss。
  • 我使用@use而不是@import。
  • color: #f22437color: $clr-primary
    Error: Undefined variable.
       ╷
    54 │   color: $clr-primary;
       │          ^^^^^^^^^^^^
       ╵
      scss/layouts/_navigation.scss 54:10  @use
      scss/layouts/_all-layouts.scss 11:1  @use
      scss/main.scss 7:1                   root stylesheet
    
    有问题的文件。
    Error Image
    File Structure
    更新我将所有@use更改为@import,并且它起作用了。
    请我理解为什么这样有效,以及如何使用@use代替@import。似乎是与SASS相关的问题,但我仍然可能有错。现在,我将“破解”它。

    最佳答案

    首先:@use当前仅适用于Dart Sass,不适用于LibSass或Ruby Sass。有关最新兼容性,请参见https://sass-lang.com/documentation/at-rules/use
    第二个:
    _variables.scss $text-colour: #262626; _otherFile.scss

    @use 'variables';
    
    body {
      color: variables.$text-colour;
    }
    
    在这里检查@whiscode答案:https://stackoverflow.com/a/61500282/2470685

    关于css - 如何修复SCSS中的 undefined variable 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64980432/

    相关文章:

    html - SASS - 垂直居中时间轴内容

    types - 确保类型在 Go 编译时实现接口(interface)

    haskell - Haskell非类型变量参数错误

    css - Sass - 过渡悬停在多个元素上

    html - Div 边距总是在页面右侧

    html - 颜色代码 "bordercolor"的 HTML 表格属性 "border-color"和 CSS 样式 "#CACACA"输出的颜色差异

    java - 为什么 Java 增量运算符允许在没有显式转换的情况下进行缩小操作?

    css - 在 twitter bootstrap 3 中分配背景颜色

    javascript - 取决于媒体查询的通用参数

    node.js - 无法安装 node-sass npm 模块