Home > Back-end >  Create react app throwing errors 'unable to resolve dependency tree' and 'fix upstrea
Create react app throwing errors 'unable to resolve dependency tree' and 'fix upstrea

Time:04-12

I've been trying use create react app but when I go to create it in the terminal i get this error.

Installing template dependencies using npm...
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
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/[email protected]
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 /Users/chrisheibel/.npm/eresolve-report.txt for a full report.

npm ERR!`

I've tried using --legacy-peer-deps and --force with no luck. It will create the app but npm start does not work. Once i've created it i've tried to install/update npm and node again with no luck. I've also uninstalled node and npm globally on my computer and reinstalled with no luck, as well as turning react and react-dom in the created app to version 17 instead of 18 but had no luck there.

I'm at a bit of a loss on this one as create react app has always worked on my computer before. But maybe you guys might know if i'm missing something here and that's why I can't run npm start/ am getting all these errors.

CodePudding user response:

The error message is telling you what the issue is. The important parts are:

Found: [email protected]

and

peer react@"<18.0.0" from @testing-library/[email protected]

So @testing-library/[email protected] is only compatible with react <18 and you have added react 18, which breaks this rule. Upgrade @testing-library/react to a compatible version or downgrade react to < 18.

the latest version of @testing-library/react is 13. so you should likely have something like

"@testing-library/react": "^13.0.0"

in your package.json

CodePudding user response:

I'd check your version of create-react-app

create-react-app --version

Mine says 5.0.0.

The documentation says to uninstall create-react-app and run it using npx. Running with npx will install the latest version:

npm uninstall -g create-react-app
npx create-react-app your-app-name

When I run create-react-app today I get a react v18 app. In some cases I've had to downgrade it to v17. I've done this as follows:

npm uninstall react react-dom
npm install react@!7 react-dom@17
  • Related