【问题标题】:SASS compile error: undefined variable [duplicate]SASS编译错误:未定义的变量[重复]
【发布时间】:2015-05-25 11:03:59
【问题描述】:

我正在使用Koala 编译 SASS 并收到以下错误:

C:.....\HTML\scss\style.scss
Error: Undefined variable: "$font-primary".
        on line 2 of C:...../HTML/scss/_base.scss
        from line 7 of C:.....\HTML\scss\style.scss
  Use --trace for backtrace.

编辑 - 作为参考,这里是我目前使用的代码 sn-ps:

style.scss

// Vendor
@import url(http://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
@import 'vendor/foundation';
@import 'vendor/normalize';

// Base
@import 'base';
@import 'mixins';
@import 'variables';

// Layout
@import 'header';
@import 'footer';

_variables.scss

// Colours
$black:         #2e2e2e;
$cream:         #fcfbf5;
$green:         #b2ca9d;
$green-dark:    #4d6638;
$grey-light:    #808080;
$grey:          #4f4f4f;
$pink-light:    #f8d8d8;
$pink:          #f0acac;
$pink-dark:     #835151;
$white:         #ffffff;

// Fonts
$font-primary:  'Droid Serif', serif;

_base.scss

body {
    font-family: $font-primary;
    line-height: 1.5;
    color: $black;
}

h1, h2, h3, h4, h5, h6 {
    font-family: $font-primary;
    text-transform: uppercase;
    letter-spacing: 0.1rem;
}

h1, h2 {
    font-size: 2.25rem;
}

.image-replace {
    width: 100%;
    height: 0;
    display: inline-block;
    font: 0/0 a;
    text-shadow: none;
    color: transparent;
    border: 0;
    background-color: transparent;
}

我的问题是变量 $font-primary 肯定是在 _variables.scss 中定义的(它也肯定被导入到我的主要 style.scss 中)所以我真的很困惑错误是如何/为什么发生的生成。

我检查了我所有文件的编码,它们使用的是没有 BOM 的 UTF-8,这是 other similar questions 中的建议修复。

顺便说一下,这是 _base.scss 中引用的第一个变量。如果我删除引用,错误仍然存​​在,但会转移到文件中的下一个变量引用。

提前致谢!

【问题讨论】:

  • 这里需要有足够的代码来重现错误。
  • 公平点。我已经从有问题的三个 .scss 文件中添加了代码。
  • 天哪,这让我快疯了!谢谢!

标签: compilation compiler-errors sass


【解决方案1】:

我认为您只需要重新排序包含,在调用 _base.scss 之前调用 _variables.scss:

// Base 
@import 'variables';
@import 'base'; 
@import 'mixins'; 

【讨论】:

  • 是的,OP 已经承认这是另一个问题的重复。与另一个问题重复的问题应该关闭,而不是回答。
猜你喜欢
  • 1970-01-01
  • 2014-04-20
  • 2014-08-09
  • 2018-05-10
  • 2014-03-21
  • 1970-01-01
  • 2016-04-27
  • 2021-09-11
  • 2014-10-09
相关资源
最近更新 更多