最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - SassError: Undefined variable: "$main-background-color" - Stack Overflow

programmeradmin4浏览0评论

I'm trying to use CSS-variables during the LoginPage ponent styling but receiving the following error: SassError: Undefined variable: "$main-background-color". This error appears in the _styles.scss file.

this is my project structure:

I'm importing both _variables.scss and styles.scss to the main index.scss file:

What I'm doing wrong while importing variables? Why I can't use them in the _styles.scss file?

I'm trying to use CSS-variables during the LoginPage ponent styling but receiving the following error: SassError: Undefined variable: "$main-background-color". This error appears in the _styles.scss file.

this is my project structure:

I'm importing both _variables.scss and styles.scss to the main index.scss file:

What I'm doing wrong while importing variables? Why I can't use them in the _styles.scss file?

Share Improve this question asked Feb 22, 2020 at 17:01 KarenKaren 1,4295 gold badges26 silver badges50 bronze badges 1
  • Path to the file is wrong from what I can tell here. Should be ../general – Phix Commented Feb 23, 2020 at 20:07
Add a ment  | 

2 Answers 2

Reset to default 5

I believe you need to import the _variables.scss directly into _styles.scss if you want to use them there

Is $main-background-color your css variable (as in custom property) or did you define it as a Sass variable?

If it is an actual css variable/custom property you need to use it like this: var(--main-background-color) and as a global variable it needs to be defined at :root {} or any other top element like <body> or <html>.

If it is a Sass variable you need to make sure which file you're trying to pile. You can't pile _styles.scss on its own, it has to be index.scss and you need to make sure that your piler isn't trying to pile modules (files starting with _) first as this would of course fail.

The @import mand basically just copies everything together so loading it in multiple locations would add this multiple times. Sass modules avoid this with heir @use mand but this is only supported in Dart Sass and not LibSass.

发布评论

评论列表(0)

  1. 暂无评论