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:
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"
},
...
}
}
This question is related to
reactjs
webpack
sass
create-react-app
node-sass
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
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.
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]
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.
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.
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:
Uninstall node-sass
npm uninstall node-sass
use sass by:
npm install -g sass
npm install --save-dev sass
It worked for me after adding particular version of node-sass package ([email protected])
This is version problem, install the right dependant version
npm uninstall node-sass
npm install [email protected]
Source: Stackoverflow.com