SASS 'Invalid css error' when using variable from imported module

非 Y 不嫁゛ 提交于 2020-07-22 17:37:44

问题


I'm really new to Sass and having problems when importing variables from partial stylesheets. I thought it was pretty straightforward, but it seems not to be the case.

I'm using this stylesheet in a react component, importing like this:

import '../stylesheets/Table.scss';

The actual stylesheet (simplified, but with the same error) looks like this:

@use 'colors.scss';

.datatb-container {

    background-color: colors.$table-bg;
    border: 2px solid colors.$table-border;

    border-radius: 2px;
    padding: 1.2%;
    max-width: 40rem;
}

And the file where my variables are located is called _colors.scss, in the same directory as Table.scss, and looks like this:

// App colors
$highlight: rgb(197, 145, 0);

// Table colors
$cell-bg: white;
$table-bg: gainsboro;

$cell-border: gray;
$table-border: black;

When I run React, I get the following error:

SassError: Invalid CSS after "...ound-color: color": expected expression (e.g. 1px, bold), was ".$table-bg;"
        on line 4 of ./src/stylesheets/Table.scss
>>     background-color: color.$table-bg;

I already tried changing directories, using the variables in different ways, changing the namespace with @use 'colors' as {smth}, but I always get the error.

What am I doing wrong?


回答1:


The @use is not currently supported in node-sass (as of v4.14.1) and is only available in dart-sass



来源:https://stackoverflow.com/questions/62886316/sass-invalid-css-error-when-using-variable-from-imported-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!