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

Zek*_*hak 5 javascript node.js npm reactjs semantic-ui

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\_logs\2022-05-01T18_07_14_536Z-debug-0.log
Run Code Online (Sandbox Code Playgroud)

Jim*_*mmy 6

TLDR: semantic-ui-react@2.1.2 is incompatible with React 18. As a workaround, you can downgrade your application to React 17.

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
Run Code Online (Sandbox Code Playgroud)

Those first three lines indicate that npm identified React 18 as your project's dependency.

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
Run Code Online (Sandbox Code Playgroud)

These 3 lines list semantic-ui-react's peer dependency, meaning it expects your project to have either React 16.8 or React 17 as dependency.

Fix the upstream dependency conflict

There are two ways to address this conflict:

  1. Downgrade your project to React 17 using npm install react@17
  2. Override semantic-ui-react's using yarn's Selective Resolution feature. Inside your package.json:
"resolutions": {
    "semantic-ui-react/react": "^18.0.0"
}
Run Code Online (Sandbox Code Playgroud)