9

Installing template dependencies using npm:

npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: [email protected]
npm error Found: [email protected]
npm error node_modules/react
npm error   react@"^19.0.0" from the root project
npm error
npm error Could not resolve dependency:
npm error peer react@"^18.0.0" from @testing-library/[email protected]
npm error node_modules/@testing-library/react
npm error   @testing-library/react@"^13.0.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
8
  • 1
    which command are you using for installing template dependencies? Share all details. Commented Dec 6, 2024 at 4:24
  • 1
    create-react-app is garbage, don't use it Commented Dec 6, 2024 at 4:35
  • @AmitVerma I have the same issue. "npx create-react-app myappname". Then got the similar error. Commented Dec 6, 2024 at 5:19
  • @test1229 have u tried the command with --force or --legacy-peer-deps as mentioned in above error log ? It resolves many problems. Commented Dec 6, 2024 at 6:54
  • 4
    The release of React 19 has broken the dependency tree CRA is trying to create. It's no longer maintained, and this situation will only get worse - use e.g. Vite instead. Commented Dec 6, 2024 at 10:36

6 Answers 6

6

Consider switching to Vite.

Here's how to set up a new React project using Vite:

# Create new Vite project
npm create vite@latest my-react-app

# Navigate to project directory
cd my-react-app

# Install dependencies
npm install

# Start dev server
npm run dev

https://github.com/facebook/create-react-app/issues/13717#issuecomment-2537222504

Sign up to request clarification or add additional context in comments.

Comments

6

React v19 has an issue while installing @testing-library/react. To temporarily resolve this dependency issue, you can set legacy-peer-deps flag to true so that it resolves the peer dependency conflicts. You can do this by running:

npm config set legacy-peer-deps true

1 Comment

This helped me. Thanks so much!
3

the first step is to locate your project folder

then run these commands one by one

npm uninstall react react-dom

then

npm install react@18 react-dom@18

then

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

then

npm start

or you can go with this YouTube link: https://youtu.be/mUlfo5ptm1o?si=hYHTwc7hApEXzPX5

Comments

2

If you really need the lib @testing-library/react. You can install it with the command: npm i @testing-library/react.

PS: The @testing-library/[email protected] requires react@"^18.0.0" and the create-react-app is using react 19

Comments

0
  1. Delete node_modules
  2. Include "@testing-library/react": "^16.1.0" dependency in package.json
  3. npm i

Comments

-1
yarn create react-app my-app --template typescript

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.