Hey everyone, I’m new to React and I’m having some trouble setting up my project. I tried to create a new React app using npx create-react-app
, but I’m getting dependency conflicts. The main issue seems to be with React version 19.0.0 and @testing-library/react which needs React 18.0.0.
Here’s what I’ve tried:
npx create-react-app my-react-app
cd my-react-app
npm install
But I keep getting an ERESOLVE error. It mentions something about fixing upstream dependency conflicts or using --force or --legacy-peer-deps.
I also tried installing the testing libraries and web-vitals separately, but no luck:
npm install @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
Any ideas on how to fix this? I’m not sure if I should downgrade React or update the testing library. Help would be much appreciated!
I’ve run into similar dependency conflicts before and found a workaround with pnpm. I’ve switched from npm to pnpm mainly because it handles dependency resolution more gracefully. I installed pnpm globally and then created my React app using pnpm’s version of create-react-app. After moving into the project directory, I ran the install command and it worked much smoother.
Whenever version conflicts persist, explicitly installing React and React DOM at version 18.2.0 can resolve the issues. This approach has saved me considerable troubleshooting time and helped maintain a more stable project setup.
I encountered a similar issue recently. The conflict between React 19 and the testing libraries is a known problem. Instead of using ‘npx create-react-app’, I’d recommend initializing your project with Vite. It’s faster and avoids many of these dependency conflicts.
Here’s what worked for me:
npm create vite@latest my-react-app – --template react
cd my-react-app
npm install
This approach sets up a modern React project without the compatibility issues. If you specifically need create-react-app, consider specifying an older React version during installation:
npx create-react-app my-react-app --use-npm --scripts-version 5.0.1
This version is stable and should work with the current testing libraries. Hope this helps!
hey ryan, sry to hear ur having issues. have u tried clearing ur npm cache? sometimes that helps. also, maybe try using yarn instead of npm? it handles dependencies differently. if all else fails, u could try the --force flag, but be careful with that. good luck!