score:1119

Accepted answer

TL;DR

  1. npm uninstall node-sass
  2. npm install sass

Or, if using Yarn

  1. yarn remove node-sass
  2. yarn add sass

Edit3: yes, another edit. Moving to sass (dart-sass) is the best solution. Previous one included locking node-sass to version 4.x.x, which is 2 years old and lacks newer SCSS features.


Edit2: sass-loader v10.0.5 fixes it. The problem is you might not be using it as a project dependency, but more as a dependency of your dependencies. CRA uses a fixed version, angular-cli locks to node-sass v4, and so on.

The recommendation for now is: if you're installing just node-sass, check the below workaround (and the note). If you're working on a blank project and you can manage your Webpack configuration (not using CRA or a CLI to scaffold your project), install the latest sass-loader.


Edit: this error comes from sass-loader. There is a semantic versioning mismatch since node-sass @latest is v5.0.0 and sass-loader expects ^4.0.0.

There is an open issue on their repository with an associated fix that needs to be reviewed. Until then, refer to the solution below.


Workaround: don't install node-sass 5.0.0 yet (the major version was just bumped).

Uninstall node-sass

npm uninstall node-sass

Then install the latest version (before 5.0)

npm install node-sass@4.14.1


Note: LibSass (hence node-sass as well) is deprecated and dart-sass is the recommended implementation. You can use sass instead, which is a Node.js distribution of dart-sass compiled to pure JavaScript.

score:-3

Steps to resolve this issue:

  1. Go to your node_module folder and open node-sass modules.

  2. In the package.json file inside node-sass, change the version from "5.0.0" to "4.14.1".

  3. Finally in the package.json at the root of the main project again change node-sass version from "5.0.0" to "4.14.4."

This should work.

score:0

In app.js or wherever the css is being imported, make sure to import css and not scss. The script in package.json will create a css file and that's what should be imported.

    "scss": "node-sass --watch -include-path src/scss -o src/css"

This script will watch a scss file inside of a folder called scss that is inside src. It will then create an css folder inside src and add a css file inside that folder, this is the file you should import in app.js

To run the script:

npm run scss

File structure example: src/scss/styles.scss

CSS file created by script: src/css/styles.css

score:0

Or else Rebuild your node-sass so that the compatibility does not produce an error. When the incompatibility between node-sass and node occurs, you will get typescript errors . Do this to achieve node-sass compatibility.

npm rebuild node-sass

score:0

This error is due to an incompatible version of the sass loader with node-sass.

Add these dependencies at the end of your package.json file.

Note: You can google to check which sass-loader version is compatible with your node-sass version.

"devDependencies": { "node-sass": "^6.0.1", "sass-loader": "^10.2.0" }

score:0

Updated answer


Please note Node Sass is depreciated and you may replace it by Dart Sass:

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.

Source: https://www.npmjs.com/package/node-sass

The below recipe helped me:

  1. Uninstall node-sass:
    • npm: npm uninstall node-sass
    • yarn: yarn remove node-sass
  2. Uninstall sass-loader:
    • npm: npm uninstall sass-loader
    • yarn: yarn remove sass-loader
  3. Install Dart Sass as a development dependency
    • npm: npm install sass -dev
    • yarn: yarn add sass -dev

Before build, you should also:

  1. Remove node_modules directory
  2. Remove lock file:
    • npm: Remove package-lock.json
    • yarn: Remove yarn.json

score:1

Small update: In case if you get the below error in regard to node-sass, follow the steps given below.

code EPERM npm ERR! syscall unlink

Steps to solve the issue:

  1. Close Visual Studio
  2. Manually remove .node-sass.DELETE from node_modules
  3. open Visual Studio
  4. npm cache verify
  5. npm install node-sass@4.14.1

score:1

Just change version to: "version": "4.14.1" in your package.json file

score:1

Adding sass-loader as as dev-dependency solved this for me. "devDependencies": { "node-sass": "^6.0.0", "sass-loader": "^11.1.1" }

score:1

Delete a yarn.lock file in the project and

yarn remove node-sass
yarn add node-sass

score:2

If the error is

Error: Node Sass version 5.0.0 is incompatible with ^4.0.0

Step1: stop the server

Step2: run commands are npm uninstall node-sass

Step3: check node-sass in package.json if node-sass is available in the file then again run Step2.

Step4: npm install node-sass@4.14.1 <=== run command

Step5: wait until the command successfully runs.

Step6: start-server using npm start

score:2

I met the same issue, and here's how I was able to fix it:

Firstly, you have to know which node-sass version you are using in your project. Then go upgrade or downgrade your current Node.js version to the compatible version with your current node-sass version, you can know that from this link.

Of course, stop the server, and close your IDE.

So, the best way to upgrade or downgrade the Node.js version, has mentioned above in this answer. Then remove the node_modules, and package-lock.json and install again... You can do it as such:

npm cache clean --force

rm -rf /node_modules package-lock.json

npm install

npm audit fix

npm run <your_script_name>

score:2

You can just switch to sass since node-sass is deprecated now anyway

in your package.json

"node-sass": "npm:sass@^1.49.9",

React still asks for node-sass after removing it and replacing with sass so you can alias it like this and now react will use sass

score:4

It worked for me after adding particular version of node-sass package (node-sass@4.14.1)

score:4

According to the Edit2 of Nicolas Hevia telling that

sass-loader v10.0.5 fixes it

I launched this command:

npm install sass-loader@^10.0.5 node-sass --save-dev

That fixed my issue.

Be aware that I am in a development environment. In other cases, the option --save-dev should be removed.

score:5

This is version problem. Install the right dependent version:

npm uninstall node-sass
npm install node-sass@4.14.1

score:7

Using npm,

  1. npm uninstall node-sass
  2. npm install node-sass
  3. change the "react-scripts": "4.0.0" into "react-scripts": "4.0.3" in package.json and save
  4. npm install
  5. npm start

or, using yarn -

  1. yarn remove node-sass
  2. yarn add --dev node-sass
  3. as above
  4. yarn install
  5. yarn start

score:13

If you happen to use CRA with the default Yarn package manager, use the following. It worked for me.

yarn remove node-sass
yarn add node-sass@4.14.1

score:19

The best solution for me was uninstalling node-sass.

npm uninstall node-sass

then install sass:

npm install sass

For those using Yarn:

yarn remove node-sass
yarn add sass

score:50

node-sass aka LibSass is officially deprecated as of October 26 2020 and instead you should use sass aka Dart Sass.

For npm you could do:

npm uninstall node-sass
npm install sass --save-dev

For yarn do:

yarn remove node-sass
yarn add sass

score:60

Uninstall node-sass:

npm uninstall node-sass

Use sass by:

npm install -g sass
npm install --save-dev sass

score:98

The only one reason why you get some error like that, is because your Node.js version is not compatible with your node-sass version.

So, make sure to checkout the documentation at node-sass.

Or this image below will be help you in deciding what Node.js version can use the node-sass version.

Enter image description here

For an example, if you're using Node.js version 12 on your Windows system ("maybe"), then you should have to install the node-sass version 4.12.

npm install node-sass@4.12

Yeah, like that. So now you only need to install the node-sass version recommended by the node-sass team with Node.js version installed on your computer.


Related Query

More Query from same tag