Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 450
Dodilei Avatar asked Apr 24 '26 13:04

Dodilei


2 Answers

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

like image 131
nschonni Avatar answered Apr 27 '26 03:04

nschonni


UPDATE: node-sass version 6.0 supports @use

like image 38
Simen L Avatar answered Apr 27 '26 04:04

Simen L



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!