繁体   English   中英

npm 错误。 代码 ERESOLVE npm 错误! ERESOLVE 无法解析。 当我运行 npm 安装时

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

当我运行“npm install”从克隆的存储库安装依赖项时,我从终端收到以下错误。 我用 windows 10

npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: react-scripts@4.0.0
npm ERR! Found: typescript@4.1.3
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 react-scripts@4.0.0
npm ERR! node_modules/react-scripts
npm ERR!   react-scripts@"4.0.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: typescript@3.9.10
npm ERR! node_modules/typescript
npm ERR!   peerOptional typescript@"^3.2.1" from react-scripts@4.0.0
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_

即使当我运行npm install --legacy-peer-deps时,我仍然会遇到同样的错误。 请问什么可能是错的?

这是我的 package.json 文件中的内容:

}
 ]
  "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"
  ]
}

该错误告诉您react-scripts@4.0.0支持typescript@^3.2.1 (即 TypeScript >=3.2.1, <4)作为对等依赖项。

您的开发依赖项中有 TypeScript 4(不是 3.2.x),该版本的 react-scripts 不支持,因此解析错误。

react-scripts 的当前版本是 5.0.1 ,所以我建议将 react-scripts 升级到该版本(只需将 package.json 中的"4.0.0"更改为"5.0.1" )并重试,因为那版本声明支持 TypeScript 4

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM