I've created a blank React project, using the command: npx create-react-app on npm v7.0.7 and Node.js v15.0.1
Installed:
React v17.0.1,
node-sass v5.0.0,
Then I tried to import a blank .scss file to the App component:
File App.js
import './App.scss'
function App() {
return (
<div className="App">
App
</div>
);
}
export default App;
It throws 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.
File 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"
},
...
}
}
TL;DR
npm uninstall node-sass
npm install sass
Or, if using Yarn
yarn remove node-sass
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.
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.
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.
Uninstall node-sass:
npm uninstall node-sass
Use sass by:
npm install -g sass
npm install --save-dev sass
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
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
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
Using npm,
npm uninstall node-sass
npm install node-sass
change the "react-scripts": "4.0.0" into "react-scripts": "4.0.3" in package.json and save
npm install
npm start
or, using yarn -
yarn remove node-sass
yarn add --dev node-sass
as above
yarn install
yarn start
This is version problem. Install the right dependent version:
npm uninstall node-sass
npm install node-sass#4.14.1
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.
It worked for me after adding a particular version of the node-sass package (node-sass#4.14.1).
You can just switch to Sass since node-sass is deprecated now anyway.
In your package.json file:
"node-sass": "npm:sass#^1.49.9",
React still asks for node-sass after removing it and replacing it with Sass, so you can alias it like this and now React will use Sass.
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>
If the error is
Error: Node Sass version 5.0.0 is incompatible with ^4.0.0
Step 1: stop the server
Step 2: run commands are npm uninstall node-sass
Step 3: check node-sass in package.json. If node-sass is available in the file then again run Step 2.
Step 4: npm install node-sass#4.14.1 <=== run command
Step 5: wait until the command successfully runs.
Step 6: start-server using npm start
Just change version to:
"version": "4.14.1" in your package.json file
Adding sass-loader as as dev-dependency solved this for me.
"devDependencies": { "node-sass": "^6.0.0", "sass-loader": "^11.1.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:
Close Visual Studio
Manually remove .node-sass.DELETE from node_modules
open Visual Studio
npm cache verify
npm install node-sass#4.14.1
Delete a yarn.lock file in the project
and
yarn remove node-sass
yarn add node-sass
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
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
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"
}
Please note that Node Sass is deprecated and you may replace it with 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: node-sass
The below recipe helped me:
Uninstall node-sass:
npm: npm uninstall node-sass
yarn: yarn remove node-sass
Uninstall sass-loader:
npm: npm uninstall sass-loader
yarn: yarn remove sass-loader
Install Dart Sass as a development dependency
npm: npm install sass -dev
yarn: yarn add sass -dev
Before building, you should also:
Remove the node_modules directory
Remove lock file:
npm: Remove package-lock.json
yarn: Remove yarn.json
npm uninstall node-sass
npm i sass
Steps to resolve this issue:
Go to your node_module folder and open node-sass modules.
In the package.json file inside node-sass, change the version from "5.0.0" to "4.14.1".
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.
I want to install SASS to my react app.
I try yarn add node-sass my console return error:
./src/comopnents/Form/Form.scss (./node_modules/css-loader??ref--6-oneOf-5-1!./node_modules/postcss-loader/src??postcss!./node_modules/sass-loader/lib/loader.js!./src/comopnents/Form/Form.scss)
Node Sass version 7.0.1 is incompatible with ^4.0.0.
I found advice to uninstall node-sass and install sass. I did it, but then I have got this error:
../src/comopnents/Form/Form.scss (./node_modules/css-loader??ref--6-oneOf-5-1!./node_modules/postcss-loader/src??postcss!./node_modules/sass-loader/lib/loader.js!./src/comopnents/Form/Form.scss) To import Sass files, you first need to install node-sass. Run npm install node-sass or yarn add node-sass inside your workspace. Require stack:
/Users/madlen/(...)/node_modules/sass-loader/lib/loader.js
/Users/madlen/(...)/node_modules/loader-runner/lib/loadLoader.js
/Users/madlen/(...)/node_modules/loader-runner/lib/LoaderRunner.js
/Users/(...)/node_modules/webpack/lib/NormalModule.js
/Users/(...)/node_modules/webpack/lib/NormalModuleFactory.js
/Users/(...)/node_modules/webpack/lib/Compiler.js
/Users/(...)/node_modules/webpack/lib/webpack.js
/Users/(...)/node_modules/react-scripts/scripts/start.js
I try to upgrate yarn, add sass-loader, nothing helps
Do this 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
Maybe try updating your project's react-scripts, as doing so fixed the issue for me.
I was having the same issue - saw advice elsewhere to switch node-sass out for sass, and then had the same errors mentioned in the OP. Tried Mark O's solution to alias sass, which worked. However, then I tried setting up absolute imports in my project (with jsconfig.json in the way described here), and that was mysteriously failing too.
I then realized that my project had a very old version of react-scripts for some reason, as it was on 2.x.x. So I swapped react-scripts in my package.json to be "react-scripts": "4.0.3", ran npm install, did npm run start and now absolute imports work. I then tried using sass instead of node-sass again and that works too (npm uninstall node-sass, then npm install sass).
try stopping the current development server, and install node-sass again.
I was having similar problem. These steps fixed my problem.
Delete node_modules rm -rf node_modules
Delete package-lock.json rm package-lock.json
Run npm install or yarn install
I am using;
node-sass: ^6.0.1
npm: 7.24.2
node: v16.13.0
I have the following error with npm start in my React application:
The react-scripts package provided by Create React App requires a dependency:
"webpack-dev-server": "3.11.1"
Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack-dev-server was detected higher up in the tree:
C:\Users\Username\node_modules\webpack-dev-server (version: 3.11.0)
Usually I fixed this type of issue by running the following code: npm install react-scripts#latest.
But now it seems like that React is not updated yet to the latest webpack-dev-server
Now the question is how to fix that. By the way, I use npx create-react-app for my project, Thanks!
I have write following commands in react project
Open project in command prompt
npm uninstall -g webpack-dev-server
remove web-dev-server folder from node_modules(C:/Users/UserName/Node_Modules)
npm i -g webpack-dev-server#3.11.1
remove package-lock.json and write npm install
after it your react project may be start by npm start
First, remove the node_modules folder and yarn-lock or package-lock.json file.
And, then add this line in your .env file:
SKIP_PREFLIGHT_CHECK=true
Now you can do npm start or yarn start after re-installing the packages. It should work.
Explanation:
For some reasons, you have two versions of webpack-dev-server installed in your project's node_modules. By setting SKIP_PREFLIGHT_CHECK=true in .env file, we are telling npm to ignore such version issues.
Check if node_modules and package-lock.json are present in your home folder, instead of your project folder. If yes, delete those two folders and then go for npm start.
We have a project using #material-ui. It's built upon:
create-react-app: 3.4
node: 10.18.1
yarn: 1.21.1
#material-ui: 4.9.x
This problem is weird: i can yarn start and yarn build locally, the versions are exactly the same as server. However, after I push to server, it failed:
[4/4] Building fresh packages...
success Saved 1 new dependency.
info Direct dependencies
└─ #material-ui/icons#4.9.1
info All dependencies
└─ #material-ui/icons#4.9.1
Done in 8.27s.
+ yarn run build:dev
yarn run v1.21.1
$ cp .env.sample .env && react-scripts build
The following changes are being made to your tsconfig.json file:
- compilerOptions.paths must not be set (aliased imports are not supported)
Creating an optimized production build...
Failed to compile.
./node_modules/#material-ui/icons/esm/index.js
Cannot find module: './AccessAlarm'. Make sure this package is installed.
You can install this package by running: yarn add ./AccessAlarm.
The building steps on server is:
node -v
rm yarn.lock
rm -rf build node_modules
yarn install
yarn add #material-ui/core // I have tried to run with and w/o these two lines
yarn add #material-ui/icons
yarn run build:dev
Anyone has any ideas about this? Thanks.
yarn cache clean does the trick.
In my case the error was occuring locally and this is what fixed it:
yarn add #material-ui/core
Then
yarn link
Then
yarn upgrade #material-ui/core
Then
yarn upgrade #material-ui/icons
Then
npm start
I am trying to use sass in my reactjs project and I tried
npm install node-sass
after install and import it with scss extension but not working it,
I used W3Schools Tutorial but still not working
error showing this
./src/myStyle.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/myStyle.scss)
To import Sass files, you first need to install node-sass.
Run `npm install node-sass` or `yarn add node-sass` inside your workspace.
The error is:
Run npm install node-sass or yarn add node-sass inside your workspace.
This means that the node-sass was not found inside the node_modules folder of the reactjs project.
This problem can be fixed by explicitly installing node-sass inside the project folder (using --save option along with npm install inside the project folder)
cd react-js-project-folder
npm install --save node-sass
npm install --save node-sass must be run in the root of the react-js project, I.E., at the same folder where package.json is located.