问题
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