michy David
michy David

Reputation: 21

npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve. When I ran npm install

When I run 'npm install' to install the dependencies from a cloned repository I get the error below from the terminal. I use windows 10

npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/typescript
npm ERR!   dev typescript@"4.1.3" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional typescript@"^3.2.1" from [email protected]
npm ERR! node_modules/react-scripts
npm ERR!   react-scripts@"4.0.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/typescript
npm ERR!   peerOptional typescript@"^3.2.1" from [email protected]
npm ERR!   node_modules/react-scripts
npm ERR!     react-scripts@"4.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 C:\Users\USER-PC\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\USER-PC\AppData\Local\npm-cache\_logs\2022-10-04T10_18_32_

Even when I ran npm install --legacy-peer-deps I still get same error. Please what could possibly be wrong?

And here's the content in my package.json file:

}
 ]
  "name": "info-site",
  "version": "1.0.0",
  "description": "",
  "keywords": [],
  "main": "src/index.js",
  "dependencies": {
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-scripts": "4.0.0"
  },
  "devDependencies": {
    "@babel/runtime": "7.13.8",
    "typescript": "4.1.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

Upvotes: 1

Views: 8523

Answers (2)

Michael Steshenko
Michael Steshenko

Reputation: 13

The solution is to udpate to latest version of react-scripts.
For some reason running npm update didn't resolve the error, so I reinstalled manually (which installs the latest version).
run npm remove react-scripts
then run npm install react-scripts

Upvotes: 1

AKX
AKX

Reputation: 168967

The error is telling you that [email protected] supports typescript@^3.2.1 (i.e. TypeScript >=3.2.1, <4) as a peer dependency.

Your dev dependencies have TypeScript 4 (not 3.2.x) in them, which is not supported by that version of react-scripts, hence the resolution error.

The current version of react-scripts is 5.0.1, so I'd recommend upgrading react-scripts to that version (simply by changing that "4.0.0" in your package.json to "5.0.1") and trying again, since that version declares support for TypeScript 4.

Upvotes: 5

Related Questions