Skip to main content

How to Fix "ERESOLVE Unable to Resolve Dependency Tree" Error While Creating a React App

How to Fix Dependency Errors While Creating a React App

If you're trying to set up a React app using npx create-react-app and encounter the following error:

npm error code ERESOLVE  
npm error ERESOLVE unable to resolve dependency tree  
npm error Found: react@19.0.0  
npm error Could not resolve dependency:  
npm error peer react@"^18.0.0" from @testing-library/react@13.4.0  

Don't worry! This issue occurs due to dependency conflicts between react, react-dom, and other packages like @testing-library/react. Below are two simple ways to fix this issue.

Step 1: Try Fixing It With npm

Before switching to Yarn, you can resolve the issue by installing the missing or incompatible dependencies manually. Here's how:

  1. After running npx create-react-app my-app, if the error appears, navigate to your project folder:
    cd my-app
  2. Install the missing web-vitals dependency:
    npm install web-vitals
  3. Check for other dependency conflicts (e.g., React version). If needed, install compatible versions of React and React DOM:
    npm install react@18.2.0 react-dom@18.2.0

Once all dependencies are resolved, start the development server:

npm start

This should fix the issue. However, if you face further dependency errors, proceed to the next solution.

Step 2: Use Yarn as an Alternative

Yarn is an alternative package manager to npm, and it often handles dependency resolution better in these cases. Follow these steps:

  1. If Yarn isn’t installed, install it globally:
    npm install -g yarn
  2. Create the React app using Yarn instead of npm:
    yarn create react-app my-app
  3. Once the setup completes, navigate to your app folder and start the development server:
    cd my-app  
    yarn start

When Should You Use Each Method?

  • If you want to stick with npm, manually resolving dependency conflicts (npm install web-vitals, react@18.2.0) is a good choice.
  • If you prefer a more streamlined setup with fewer manual fixes, Yarn is a great alternative.

Conclusion

Dependency issues can feel frustrating, but they’re manageable with the right approach. Start by resolving conflicts with npm, and if that doesn’t work, switch to Yarn for a smoother setup experience. Either way, you’ll have your React app running in no time!

Comments

Popular posts from this blog

How to Convert a Next.js Website into a PWA and TWA

🚀 Complete Guide: Converting Next.js to PWA & TWA Transform your Next.js website into a Progressive Web App and wrap it as an Android application using Trusted Web Activity. Every step explained in detail! 📋 Table of Contents What is a PWA? What is a TWA? Prerequisites & Setup Step 1: Convert Next.js to PWA Install Dependencies Configure next.config.js Create Web App Manifest Prepare App Icons Update Document Head Build and Test PWA Step 2: Wrap PWA as TWA Create Asset Links File Install Bubblewrap CLI ...

DevOps Best Practices

 # DevOps Best Practices: Your Ultimate Guide to Modern Software Development In today's fast-paced tech world, DevOps isn't just a buzzword – it's a game-changer. Let's dive into the essential practices that can transform your software development process. ![DevOps Lifecycle](https://blogger.googleusercontent.com/img/placeholder.png) ## 🔄 1. Continuous Integration (CI) - The Foundation Think of CI as your code's quality guardian. Every time developers push code, automated tests run to catch issues early. Here's what makes great CI: - Automated builds triggered with every commit - Comprehensive test suites running automatically - Code quality checks integrated into the pipeline - Quick feedback loops to developers **Pro Tip:** Start with simple automated tests and gradually build up your test suite. Remember, it's better to have a few reliable tests than many unreliable ones. ## 🚀 2. Continuous Delivery (CD) - From Code to Customer CD ensures your software ...

Ultimate Guide to Sending Data in React: Axios & Fetch Explained

Ultimate Guide to Sending Data in React using Axios and Fetch Whether you're building a login form, uploading files, or submitting a complex dataset to your backend, understanding how to send data in React is essential. In this comprehensive guide, we'll explore all the major ways to send data using Axios and the native Fetch API , including formats like JSON , form-data , x-www-form-urlencoded , and other advanced techniques. This guide is designed for developers from beginner to advanced levels, providing both theoretical understanding and practical implementation examples. By the end of this tutorial, you'll have a complete understanding of how data flows from React components to backend servers, and you'll know exactly which method to choose for different scenarios. 📌 Why Learn Different Data Formats? Before diving into implementation details, it's crucial to understand why different data formats exist...