505
votes

I've created a blank React project, using the command: npx create-react-app on npm v7.0.7 and Node v15.0.1

Installed:

  • React v17.0.1,
  • node-sass v5.0.0,

Then I tried to import blank .scss file to App component:

App.js

import './App.scss'

function App() {
  return (
    <div className="App">
      App
    </div>
  );
}

export default App;

Throw an Error:

Failed to compile.

./src/App.scss (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-6-1!./node_modules/postcss-loader/src??postcss!./node_modules/resolve-url-loader??ref--5-oneOf-6-3!./node_modules/s
ass-loader/dist/cjs.js??ref--5-oneOf-6-4!./src/App.scss)
Error: Node Sass version 5.0.0 is incompatible with ^4.0.0.

package.json

{
  "name": "react-17-node-sass-5",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.5",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "node-sass": "^5.0.0",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-scripts": "4.0.0",
    "web-vitals": "^0.2.4"
  },
 ...
 
  }
}
15

15 Answers

934
votes

TL;DR

  1. npm uninstall node-sass
  2. npm install [email protected]

Or, if using yarn (default in newer CRA versions)

  1. yarn remove node-sass
  2. yarn add [email protected]

Edit2: sass-loader v10.0.5 fixes it. 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 an so on.
The recommendation for now is: if you're installing just node-sass check 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 latest sass-loader.


Edit: this error comes from sass-loader. There is a semver 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 (major version was just bumped).

Uninstall node-sass

npm uninstall node-sass

Then install the latest version (before 5.0)

npm install [email protected]


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 distribution of dart-sass compiled to pure JavaScript. Be warned though:

Be careful using this approach. React-scripts uses sass-loader v8, which prefers node-sass to sass (which has some syntax not supported by node-sass). If both are installed and the user worked with sass, this could lead to errors on css compilation

71
votes

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

So, make sure to checkout the documentation at here: https://www.npmjs.com/package/node-sass

Or this image below will be help you, what the node version can use the node-sass version.

enter image description here

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

npm install [email protected]

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

47
votes

Uninstall node-sass

npm uninstall node-sass

use sass by:

npm install -g sass
npm install --save-dev sass
27
votes

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
10
votes

If you happen to use CRA with default yarn package manager use the following. Worked for me.

yarn remove node-sass 
yarn add [email protected]
5
votes

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
4
votes

It worked for me after adding particular version of node-sass package ([email protected])

4
votes

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
2
votes

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 [email protected] <=== run command

Step5: wait until the command successfully runs.

Step6: start-server using npm start

2
votes

This is version problem, install the right dependant version

npm uninstall node-sass
npm install [email protected]
0
votes

This error occurs when versions of NodeJS and Node Sass are not matched.

you can resolve your issue by doing as below:

- Step 1: Remove Nodejs from your computer

- Step 2: Reinstall Nodejs version 14.15.1.

- Step 3: Uninstall Node sass by run the command npm uninstall node-sass

- Step 4: Reinstall Node sass version 4.14.1 by run the command npm install [email protected]

After all steps, you can run command ng serve -o to run your application.

Node sass version 5.0.0 is incompatible with ^4.0.0.

0
votes

Small update: Incase if you get 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 [email protected]
0
votes

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

0
votes

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

-1
votes

Steps to resolve this issue:

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

2 In the package.json 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.