我无法安装“npm install semantic-ui-react semantic-ui-css”,我该怎么办?

I can't install " npm install semantic-ui-react semantic-ui-css", what should I do?

C:\reactcamp\camp-project> npm install semantic-ui-react semantic-ui-css
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: camp-project@0.1.0
npm ERR! Found: react@18.1.0
npm ERR! node_modules/react
npm ERR!   react@"^18.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.0 || ^17.0.0" from semantic-ui-react@2.1.2
npm ERR! node_modules/semantic-ui-react
npm ERR!   semantic-ui-react@"^2.1.2" 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\zekis\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\zekis\AppData\Local\npm-cache\_logs22-05-01T18_07_14_536Z-debug-0.log

TLDR: semantic-ui-react@2.1.2incompatible with React 18。作为解决方法,您可以将应用程序降级为 React 17.

解析时:camp-project@0.1.0

npm ERR! Found: react@18.1.0
npm ERR! node_modules/react
npm ERR!   react@"^18.0.0" from the root project

前三行表明 npm 将 React 18 识别为项目的依赖项。

无法解决依赖关系

npm ERR! peer react@"^16.8.0 || ^17.0.0" from semantic-ui-react@2.1.2
npm ERR! node_modules/semantic-ui-react
npm ERR!   semantic-ui-react@"^2.1.2" from the root project

这 3 行列出了 semantic-ui-react 的对等依赖,这意味着它希望您的项目具有 React 16.8React 17作为依赖项。

修复上游依赖冲突

有两种方法可以解决此冲突:

  1. 使用 npm install react@17
  2. 将您的项目降级为 React 17
  3. 使用 yarn 的 Selective Resolution feature 覆盖 semantic-ui-react。在你的 package.json:
  4. 里面
"resolutions": {
    "semantic-ui-react/react": "^18.0.0"
}

你可以使用这个 article 它帮助我解决了同样的问题,当我想安装 semantic-uireact 18 它可能会帮助你使用其他不兼容的框架反应 18