Suddenly React cannot execute the 'create-react-app' command. Why is this happening and how can I solve it?

Viewed 5119

Even --force or --legacy-peer-deps didn't work.

Transcript:

npx create-react-app my-app

Creating a new React app in /home/zahid/my-app.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...

added 1353 packages in 2m

171 packages are looking for funding
  run `npm fund` for details

Initialized a git repository.

Installing template dependencies using npm...
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: my-app@0.1.0
npm ERR! Found: react@18.0.0
npm ERR! node_modules/react
npm ERR!   react@"^18.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"<18.0.0" from @testing-library/react@12.1.5
npm ERR! node_modules/@testing-library/react
npm ERR!   @testing-library/react@"^12.0.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /home/zahid/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/zahid/.npm/_logs/2022-04-11T22_25_02_229Z-debug-0.log

npm install --no-audit --save @testing-library/jest-dom@^5.14.1 @testing-library/react@^12.0.0 @testing-library/user-event@^13.2.1 web-vitals@^2.1.0 failed
7 Answers

This is going to solve the problem:

  1. npm config set legacy-peer-deps true

    Explanation:

    The --legacy-peer-deps flag was introduced with v7 as a way to bypass peerDependency auto-installation; it tells NPM to ignore peer dependencies and proceed with the installation anyway. This is how things used to be with NPM v4 through v6.

  2. npx create-react-app my-app

npm config set legacy-peer-deps true

Executing that helped me (on Linux).

Here is what worked for me:

  • Run npx create-react-app as normal and got the errors
  • Go into the package.json file and change the React version from 18.0.0 to 17.0.0
  • Delete the node_modules folder.
  • Then run npm install.

No more errors.

This works for me

I changed this in my package.json (I downgraded the versions):

"react": "^18.0.0",
"react-dom": "^18.0.0",

To

"react": "^17.0.0",
"react-dom": "^17.0.0",

Then, remember to remove your folder /nodes_modules and run this in your project main folder:

npm i

Try to run this command first:

npm config set legacy-peer-deps true

and then type the command

npx create-react-app app-name

It worked for me.

Try this:

  1. Delete folder node_modules and file package-lock.json
  2. Go to file package.json and change both react and react-dom's version to 17.0.0
  3. Now run npm install

Things should now work as expected.

Try to run this first:

npm config set legacy-peer-deps true

And try your command again. It worked with me!

Related