reactjs - Kan inte installera beroenden på React-projekt som använder TypeScript - konfliktproblem


Varje beroende som jag försöker installera i projektet, får jag ett Typescript-konfliktproblem. Jag har försökt lösa det genom att uppdatera beroenden, nedgradera det, ta bort node_modules och package-lock.json för att installera om, men ingenting löser det.

Steg för att reproducera:

npm install axios

Felbeskrivning:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: [email 
npm ERR! Found: [email 
npm ERR! node_modules/typescript
npm ERR!   peer typescript@"*" from [email 
npm ERR!   node_modules/eslint-config-standard-with-typescript
npm ERR!     dev eslint-config-standard-with-typescript@"^34.0.1" from the root project
npm ERR!   peer typescript@">= 2.7" from [email 
npm ERR!   node_modules/fork-ts-checker-webpack-plugin
npm ERR!     fork-ts-checker-webpack-plugin@"^6.5.0" from [email 
npm ERR!     node_modules/react-dev-utils
npm ERR!       react-dev-utils@"^12.0.1" from [email 
npm ERR!       node_modules/react-scripts
npm ERR!         react-scripts@"^5.0.1" from the root project
npm ERR!   2 more (tsutils, the root project)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peerOptional typescript@"^3.2.1 || ^4" from [email 
npm ERR! node_modules/react-scripts
npm ERR!   react-scripts@"^5.0.1" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: [email 
npm ERR! node_modules/typescript
npm ERR!   peerOptional typescript@"^3.2.1 || ^4" from [email 
npm ERR!   node_modules/react-scripts
npm ERR!     react-scripts@"^5.0.1" 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.

Min package.json:

{
  "name": "front",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "@types/jest": "^29.5.5",
    "@types/node": "^20.8.2",
    "@types/react": "^18.2.24",
    "@types/react-dom": "^18.2.9",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.16.0",
    "react-scripts": "^5.0.1",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^5.55.0",
    "@typescript-eslint/parser": "^5.55.0",
    "eslint": "^8.36.0",
    "eslint-config-standard-with-typescript": "^34.0.1",
    "eslint-plugin-import": "^2.27.5",
    "eslint-plugin-n": "^15.6.1",
    "eslint-plugin-promise": "^6.1.1",
    "eslint-plugin-react": "^7.32.2",
    "typescript": "^5.2.2"
  }
}

Vad jag redan har gjort för att försöka fixa det:: Uppdatera typescript (Initial version var 5.0.1):

npm install [email 

Ta bort node_modules och package-lock.json:

rm -rf node_modules
rm -rf package-lock.json

Rensa npm-cache:

npm cache clean -f

Svar #1

Här är lite information från GitHub (https://github.com/facebook/create-react-app/issues/13080)

försök att lägga till detta i din package.json :

"overrides": {
  "typescript": "^5.0.3",
},

Svar #2

Några lösningar

Det finns en tråd på create-react-apps GitHub-repo om detta problem och några lösningar.

du kan lägga till en ny post i din package.json-fil:

"overrides":{
    "typescript": "^5.0.2"
}

eller :

"overrides": {
"react-scripts": {
  "typescript": "^5"
}

OBS

Och en annan VIKTIG not om CRA: det verkar som att detta projekt är dött. Det har gått ungefär två år utan några nya commits på projektet.