Upgrading the react router version, I got 2 in my project

Viewed 50

I am upgrading the react router version for one of my friend project

The thing is there are 2 react-router-dom. Do I need to remove both of them or just remove 1 of them is fine?

{
  "name": "root",
  "private": true,
  "devDependencies": {
    "@types/react-router-dom": "5.3.3",
  },
  "scripts": {
    "start": "nx serve",
   
  },
  "dependencies": {
    "react-router-dom": "5.3.0",
    "yup": "0.32.11"
  }
}
2 Answers

You don't have two of the same NPM package installed, @types/react-router-dom is a different package than react-router-dom. The latter is the actual react-router-dom dependency while the former is the typescript definitions for it as a dev dependency. That said, you should try to be on the same version of both as @types/react-router-dom generally matches the version of the package it's typing.

From the terminal run npm i -S react-router-dom@5.3.3 to install the same version you have the types for.

Upgrade to RRDv6

react-router-dom@6 is completely written in Typescript, so if you decide to upgrade to RRDv6 you no longer need the additional types package, installing react-router-dom@6 alone is sufficient.

Remove any @types/react-router-dom packages that are installed.

Why dont you make rm -rf node_modules to clean it up. Remove the old router version in your json and make nmp i. If needed because there is no router after the deletion of the old make npm i react-router

Related