Problems with installing SASS React - reactjs

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

Related

reactjs. Error: Node Sass version 7.0.1 is incompatible with ^4.0.0 [duplicate]

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.

process is not defined on hot reload

I have a react app made with create react app, and hot reloading kills the page entirely with the error:
Uncaught ReferenceError: process is not defined
What's strange is that there seems to be an iframe injected which I never noticed before:
This iframe is added to the DOM as soon as I reload and breaks the page as well as preventing an update. I can't find any documentation on "iframe-bundle.js" online.
Edit: I tried deleting my node modules and any questionable imports (I temporarily installed craco prior). Still the same issue. It's incredibly annoying!
Edit 2: If I delete that iframe everything seems to return to normal, i.e. page updates and is interactable
Upgrading your application to CRA (react-scripts) v5 with npm i react-scripts#latest will fix the issue.
If your app is not able to be upgraded because dependencies are incompatible or you require node version < 14, you can try the following workaround which worked for me:
Revert back to CRA 4: npm i --save-exact react-scripts#4.0.3
Add react-error-overlay as a dev dependency: npm i --save-dev react-error-overlay#6.0.9
Then add the following line to your package.json
"resolutions": {
"react-error-overlay": "6.0.9"
},
If you're using NPM, force your package-lock.json file to actually use 6.0.9 with npx npm-force-resolutions
If you're using Yarn, just run yarn install and your resolutions will be applied and fix the issue
More info at https://github.com/facebook/create-react-app/issues/11773
I fixed it. I did 2 things:
Updated npm to latest
Updated react-scripts to latest
Not sure which one fixed it.
I recently had this issue aswell.
I did couple of things to make it work. You can try these aswell.
Change the react-script version to 4.0.3 inside package.json.
Add this to package.json, below the dependencies.
"resolutions": { "react-error-overlay": "6.0.9" },
Install react-error-overlay v6.0.9 inside your devDependencies.
Remove your node_modules and package-lock.json.
Do npm install and check that works.
Note: After doing the above steps I had to run npm install react-error-overlay#6.0.9 again to fix this issue.
Make sure your react-scripts version is ^4.0.3, then install react-error-overlay as devDependencies using this command below:
npm i -D react-error-overlay#6.0.9 on NPM
yarn add -D react-error-overlay#6.0.9 on Yarn
I tried the answers above, but non of those fixed the issue for me. What I did to solve this problem in my case was:
Delete node_modules
clearing the cache -> npm cache clean --force
install the latest react-scripts version -> npm i react-scripts#latest

Cannot find module 'sass'

I write a react app and tried to dockerized it.
after i do this it doesn't compile corectly, it doesn't find "sass" module and this is my error:
Failed to compile.
./src/index.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/sass-loader/dist/cjs.js??ref--5-oneOf-6-4!./src/index.scss)
Cannot find module 'sass'
Require stack:
- /app/node_modules/sass-loader/dist/utils.js
- /app/node_modules/sass-loader/dist/index.js
- /app/node_modules/sass-loader/dist/cjs.js
- /app/node_modules/loader-runner/lib/loadLoader.js
- /app/node_modules/loader-runner/lib/LoaderRunner.js
- /app/node_modules/webpack/lib/NormalModule.js
- /app/node_modules/webpack/lib/NormalModuleFactory.js
- /app/node_modules/webpack/lib/Compiler.js
- /app/node_modules/webpack/lib/webpack.js
- /app/node_modules/react-scripts/scripts/start.js
and this is my dockerfile:
From node:14.16.1-alpine
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json ./
COPY package-lock.json ./
RUN npm install --silent
RUN npm install react-scripts#4.0.3 -g --silent
COPY . ./
CMD ["npm", "start"]
and I don't have docker-compose.
any solution?
I add this line to my docker file but it doesn't work and gets me same Error:
RUN npm install -g sass
To note! node-sass is deprecated as by now!
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.
Instead you can see that Sass is followed on the Dart sass project!
react-scripts already moved that direction!
The used package now is sass! npm i -g sass or npm i sass --save-dev
If you go to npm sass page
This package is a distribution of Dart Sass, compiled to pure JavaScript with no native code or external dependencies. It provides a command-line sass executable and a Node.js API.
You can install Sass globally using npm install -g sass which will provide access to the sass executable. You can also add it to your project using npm install --save-dev sass. This provides the executable as well as a library.
What should be done
Install sass
Globally
npm i -g sass
or
Locally
npm i sass --save-dev
I personally prefer to always go with local installs! So that npm install will add it automatically! Sometimes too to maintain the versions per project!
And
App compilling and running after install!
old version of react scripts
If you are running on an old version that require node-sass!
Then you can Update to the latest version! And before that! You may like to remove node_modules and package-lock.json.
npm i react-scripts --save
After that npm install to install again the project dependencies
And you can go for installing sass step
npm cache clear --force
npm install sass
To be clear:
1st) try uninstalling it by using this command
npm uninstall node-sass
and then 2nd) try installing sass
npm install --save-dev sass
this worked for me when I was having issues installing sass on a project using create react app
I solve it!
you just need to add this line in to your "dockerfile" so when you build your docker image it should install sass automaticly:
RUN npm install -g sass
and in your "package.json" add this in the "dependencies" that it tells to program what we have in this case we mean we have the specific version of "sass":
"sass": "version number(example:^5.0.0)"
and add this in "scripts" part that tells to program how to work in this case I think it tells that for "scss" files whatch that file and recognize and open it like a "css":
"scss": "sass --whatch scss -o css"
Try install in your terminal this
npm install --save-dev node-sass
and restart your localhost by typing
npm start
Hit Enter on your prompt
After doing these steps make sure to check your dependency go into
package.json
and find
"devDependencies": {
"node-sass": "^yourversion" }
How to add support for SCSS and SCSS modules in Webpack
npm install --save-dev node-sass sass-loader style-loader css-loader mini-css-extract-plugin
Source: https://www.developerhandbook.com/webpack/how-to-configure-scss-modules-for-webpack/#how-to-add-support-for-scss-and-scss-modules-in-webpack

Why React npm start return error for webpack-dev-server 3.11.1?

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.

Issue with babel-jest dependency when running npm start in a React app

All I am doing is running create-react-app and cd'ing into the app, then trying to run npm/yarn start. I get the following error/output/log. I have walked through all of the suggested steps. The only thing that works is the SKIP_PREFLIGHT_CHECK=true in my .env as the last resort for both
Yarn and npm. I have recently updated to Mojave and had to reinstall my Xcode if people have had a similar experience.
Last login: Tue Oct 30 16:30:24 on ttys002
TheLAB11:~ jasonspiller$ cd repos/react-express-graphql-app/
TheLAB11:react-express-graphql-app jasonspiller$ npm start
> react-express-graphql-app#0.1.0 start /Users/jasonspiller/repos/react-express-graphql-app
> react-scripts start
There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"babel-jest": "23.6.0"
Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-jest was detected higher up in the tree:
/Users/jasonspiller/node_modules/babel-jest (version: 23.4.2)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.
To fix the dependency tree, try following the steps below in the exact order:
1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
2. Delete node_modules in your project folder.
3. Remove "babel-jest" from dependencies and/or devDependencies in the package.json file in your project folder.
4. Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:
5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
This may help because npm has known issues with package hoisting which may get resolved in future versions.
6. Check if /Users/jasonspiller/node_modules/babel-jest is outside your project directory.
For example, you might have accidentally installed something in your home folder.
7. Try running npm ls babel-jest in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed babel-jest.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-express-graphql-app#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-express-graphql-app#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/jasonspiller/.npm/_logs/2018-10-30T23_09_42_358Z-debug.log
I just had the same problem. For some reason the package ended up in a node_modules directory in my home directory. It also gave me the exact same error for the jest package.
I'm not sure of the correct way to fix this as npm uninstall -g babel-jest and yarn global remove babel-jest do not do anything.
I fixed it by just blowing away the folders that cause the problem:
bash
rm -rf ~/node_modules/babel-jest ~/node_modules/jest
It would be great to know how those packages ended up there, and the proper way of getting rid of them, but for now just deleting the folders is enough to get CRA dev server running without skipping the preflight check.
This problem can occur if there is node_modules in a parent directory of the folder where you run the application. I solved the problem by deleting the node_modules directory.
I too faced a similar problem and was able to resolve the issue following below steps.
Create a .env file in your project root directory and add the following statement
SKIP_PREFLIGHT_CHECK=true
Save the file
Remove node_modules, yarn.lock, package.lock
Then reinstall node_modules with
npm install
This should work
The problem seems to have reappeared in create-react-app 3.0.0.
The react-scripts package provided by Create React App requires a dependency:
"babel-jest": "24.7.1"
As abisuq pointed out in https://github.com/facebook/create-react-app/issues/6756#issuecomment-489562571 adding a version resolutions into package.json temporarily fixes the problem.
"resolutions": {
"babel-jest": "24.7.1"
},
Update: It has been fixed in create-react-app 3.0.1. If upgrading is an option you can run
npm install --save --save-exact react-scripts#3.0.1
or
yarn add --exact react-scripts#3.0.1
run: npm ls babel-jest
got : babelk-jest#24.7.1 & babel-jest#24.8.0 installed
this means install tow babel-jest with diff version
run:npm uninstall babel-jest#24.8.0 fix my issue
I had this issue and finally solved it easily.
As probably you know, when we use create-react-app, Jest is configured by default and you don't need to install Jest (when we use Webpack, we can install Jest). So, if you use Create-react-app and install Jest by mistake:
Firstly uninstall it (remember that if you use: (npm install --save-dev jest), you can remove jest directly from Package.json or use: (npm uninstall --save-dev jest)
Delete package-lock.json (not package.json)
Delete the node_modules
npm install
Now you don't receive an error and you can easily use: (npm start) or (npm test)
Also, It is worth mentioning that I installed the following tools to write my test in React component:
(npm install --save-dev enzyme enzyme-adapter-react-16 jest-enzyme)
and wrote my test by using jest and enzyme. Then I easily use: (npm test)
Good Luck!
Ok I finally found a solution after trying everything. Here is what finally worked:
First of all, read the error message in the cmd from the beginning. They'll tell you what module is causing the problem. You probably have an older version installed on your computer. Example: babel-jest version 2.4.4
Go to your Node.js folder c:/Users/(your user)/node_modules and find that module and simply delete it.
Go back to the cmd and run npm start. You might get the same error. But it'll be for a different module. Just delete it the same way and repeat until it runs.
I fixed the issue by removing the node_modules folder and package-lock.json file from a folder that was higher than the root of the project. I had installed node_modules accidentally in a higher folder.
I had:
desktop/code/node_modules (remove this to fix)
desktop/code/package-lock.json (remove this to fix)
desktop/code/project/node_modules
desktop/code/project/package-lock.json
I was having this issue as well. When I tried to run the client using npm start, the error would occur, telling me that it required babel-jest: ^24.9.0.
I noticed that in my client, babel-jest was version ^24.9.0, but in my server, I had "jest": "^26.6.3".
All I had to do was change "jest": "^26.6.3" to "jest": "^24.9.0" in the server side source code, delete my package-lock.json as well as node_modules in server, npm install again, and good to go!
At first I installed these (my react version was "^17.0.2")
npm install --save-dev jest
npm install --save-dev enzyme enzyme-to-json
npm install #wojtekmaj/enzyme-adapter-react-17
After that, I had the same problem.
Then I did these steps :)
Added '.env' file in my project root directory and add:
SKIP_PREFLIGHT_CHECK=true
Removed node_modules & package.lock
npm install
npm start
I had the exact same issue.
What I tried was to create the react app outside the directory that had the node_modules folder.
After that, started the app with yarn start and didn't have the error anymore.
I had the same problem, and I fixed this issue. For some reason because node_modules on my local. I removed babel-jest & jest. After that, npm start. I'm not sure this solved incorrect but this correct for me.
I solved this issue by deleting the node_modules folder and package-lock.json file I accidentally had installed in the root of my user.
For me in Mac the path was:
Macintosh HD -> Users -> "My-user-name"
I discover that might be the problem by running npm ls babel-jest on terminal. That showed me that there was another babel-jest up in the tree.
After deleting these two I did npm install in my app where I previously had deleted the node_modules folder and package-lock.json.
Now it's running ok !
I fixed this by deleting node_module folder in the project directory
try this command and see which packages create conflicts in versions.
npm ls babel-jest
replace the conflicted packages with updated one of that package.
I tried all of written solutions above. But none of them worked. I solved problem by deleting "C:\node_modules" folder.
Then delete project node_modules and package-lock.json. Finally, npm install and start again. And it worked.
My react-scripts version is 4.0.3. The problem suddenly happened after installing a private remote package, which installed multiple babel packages in my project root's node_modules. I solved this by installing the problematic packages on the project root's level explicitly, so that they match the versions reported in the preflight check.
Following addings fixed it in my case. Your needed packages and versions may differ, you have to check the preflight report.
yarn add babel-jest#^26.6.0
yarn add babel-loader#8.1.0
For me its still a workaround, but i prefer this way instead of removing something in node_modules manually as suggested in https://stackoverflow.com/a/53093421/4840661.
This is the approach without deleting node_modules:
I recieved error like:
The react-scripts package provided by Create React App requires a dependency:
"jest": "26.6.0"
Don't try to install it manually: your package manager does it automatically.
However, a different version of jest was detected higher up in the tree:
First check the versions using:
npm ls babel-jest
In my case output was like this:
jest#27.0.3
└─┬ #jest/core#27.0.3
└─┬ jest-config#27.0.3
└── babel-jest#27.0.2
After that uninstall babel-jest by
npm uninstall babel-jest
(When you see the single version of babel-jest,otherwise go as versions as follows)
npm uninstall babel-jest#27.0.2
Then install required dependencies using
npm i babel-jest#version jest#version
(Where version is the one come in 1st point)
This works for me like a charm. Hope this solves you too.
Got this error in the netlify ci, here's the fix that worked for me:
this method works for any lib i got a error for eslint instead of babel-jest.
force the error to be shown by npm i -s #babel-jest/VERSION --force
replace VERSION with whatever version shows in the error(23.6.0 in this case),
the correct error message will be shown locally
use https://www.npmjs.com/package/npm-check-updates to upgrade your package.json flie with the correct versions
run ncu -u in dir of package.json after installing the npm package
globally
finally do a npm ci
this will delete the package-lock and node_modules and install the new versions based on the second step
this work for me.
clear caches in npm or yarn
remove node_modules and lock files
create .env file
add " SKIP_PREFLIGHT_CHECK=true " to an .env file in your project.
my issue was that I have both frontend and backend that I am running concurrently. I installed jest to my root project (for backend) and I guess there is collision with pre-installed react jest. I just uninstalled jest from backend and voila I am happy now. I don't have anything related with babel.
i had the similar problem and wasted my 2-3 days
The easiest way to solve this problem is :
1.go outside of src, and create .env file.
2.Inside .env file, just write this single line and save it:
SKIP_PREFLIGHT_CHECK=true
3.then npm start
Hope this helps, Happy coding!!!

Resources