npm 错误!代码 ERESOLVE npm 错误! ERESOLVE 无法解决。当我运行 npm install 时

问题描述 投票:0回答:2

当我运行“npm install”从克隆存储库安装依赖项时,我从终端收到以下错误。我用的是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_

即使我运行

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"
  ]
}
javascript node.js reactjs typescript npm
2个回答
4
投票

错误告诉您

[email protected]
支持
typescript@^3.2.1
(即 TypeScript >=3.2.1,<4) as a peer dependency.

您的开发依赖项中包含 TypeScript 4(不是 3.2.x),该版本的反应脚本不支持该版本,因此会出现解析错误。

react-scripts 的当前版本是 5.0.1,所以我建议将 React-scripts 升级到该版本(只需将 package.json 中的 "4.0.0"

 更改为 
"5.0.1"
)并重试,因为
该版本声明支持 TypeScript 4


0
投票
解决方案是更新到最新版本的react-scripts。

由于某种原因,运行
npm update

 无法解决该错误,因此我手动重新安装(安装最新版本)。
奔跑吧
npm remove react-scripts

然后运行
npm install react-scripts

    

© www.soinside.com 2019 - 2024. All rights reserved.