I've npm installed the latest node-sass, and scss files work fine until I use @use. I have a _tokens.scss file in /shared/tokens/ folder. Within _tokens.scss I have:
$colorwhite: #ffffff;
In my root folder, my App.scss looks like this:
@use "shared/tokens/tokens";
.App-header {
color: tokens.$colorwhite;
}
But I am getting this error:
./src/App.scss (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-5-1!./node_modules/postcss-loader/src??postcss!./node_modules/resolve-url-loader??ref--6-oneOf-5-3!./node_modules/sass-loader/dist/cjs.js??ref--6-oneOf-5-4!./src/App.scss)
SassError: Invalid CSS after " color: tokens": expected expression (e.g. 1px, bold), was ".$colorwhite;"
on line 26 of /Users/xxx/src/App.scss
>> color: tokens.$colorwhite;
Any ideas?
Edit: it works fine with @import
. I've also tried @use... as *
but no-go.
After you have setup your application with create-react-app (e.g. create-react-app my-app ), you can install the Sass support with npm install node-sass --save for create-react-app. You don't need to change any other configuration. Now, let's try out how Sass in React works.
Now install the node-sass module to your react project. 3. In your project src directory create an app.scss file. 4. Now add the below code in your app.js file 5. Open your app.scss file and add below sass code there.
Not anymore. The team at Facebook released create-react-app v2 and among the many improvements, they gave us the ability to use Sass and CSS Modules right out of the box, and in this tutorial you will learn how simple it is to include them in your projects using create-react-app. Let’s create a simple project to demonstrate this.
I would suggest you check your version of React first. If you are using a version of React < 16.8 then you would have to eject and configure your webpack in order to use css and scss modules. Show activity on this post.
The @use
rule is currently only supported by Dart Sass. You should use @import
instead.
You could switch to Dart Sass by taking advantage of package-aliasing
. I guess this will not work under yarn
.
First you remove the current node-sass
pkg, then run:
npm install node-sass@npm:sass
.
And you are fit to use the full features from sass
with some remarks though.
dart-sass
is slower than node-sass
.It's all up to you and this turns to be a valid option here, if you really want to use these features provided by Sass
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With