Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace Node-Sass with Dart-Sass in Create React App v3.x

Has anybody done this successfully yet? I currently have node-sass installed in my CRA project and I'm trying to replace it with dart-sass but am experiencing difficulty because the CRA error output is telling me that I need to have node-sass installed. Is there any way to let the underlying CRA config know to use my installed dart-sass package instead of node-sass?

enter image description here

like image 682
Danchez Avatar asked Sep 17 '20 17:09

Danchez


People also ask

Is Dart Sass faster than node sass?

In our test scenario, Dart-Sass(On DartVM) is the fastest, node-sass isn't that bad, and Dart-Sass(Pure JS) is terrible in terms of performance. In this particular case, two seconds is not a big deal; but consider Dart-Sass(JS) is nine times slower than Dart-Sass(Dart VM) and three times slower than node-sass.

Is node Sass deprecated?

Warning: LibSass and Node Sass are deprecated. While they will continue to receive maintenance releases indefinitely, there are no plans to add additional features or compatibility with any new CSS or Sass features. Projects that still use it should move onto Dart Sass.


Video Answer


2 Answers

There is this closed issue on CRA repository, so you probably can easily migrate from node-sass to Dart Sass just running a few commands.

First of all check your yarn.lock or package-lock.json to know if the version of the sass-loader that your react-scripts depends on is 7.2.0 or later.

If so, all that you need is run the following commands:

yarn remove node-sass
yarn add sass

In my case after that I had to remove the node_modules directory and ran the yarn install again due to an issue stating the app.

Notes:

  • The react-scripts version I'm using is 4.0.0
  • The npm lib for Dart Sass is sass
  • The use of node-sass is deprecated since 26 October 2020
like image 50
Milton Castro Avatar answered Oct 18 '22 01:10

Milton Castro


If you are using npm > 6.9 you can create an alias like so

npm install node-sass@npm:sass

it will install dart-sass and you will be able to keep your CRA configuration.

like image 38
natali-pp Avatar answered Oct 18 '22 01:10

natali-pp