在我的React JS项目中,每当我尝试安装npm时,我都会得到错误,只有当我使用npm install --forceit时,我才能工作,我如何解决所有这些错误?

np8igboo  于 2023-03-03  发布在  React
关注(0)|答案(1)|浏览(212)

这是我得到的错误

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @mui/styles@5.11.9
npm ERR! Found: react@18.2.0
npm ERR! node_modules/react
npm ERR!   react@"^18.2.0" from the root project
npm ERR!   peer react@">=16.8.0" from @emotion/react@11.10.4
npm ERR!   node_modules/@emotion/react
npm ERR!     @emotion/react@"^11.10.4" from the root project
npm ERR!     peer @emotion/react@"^11.0.0-rc.0" from @emotion/styled@11.10.4
npm ERR!     node_modules/@emotion/styled
npm ERR!       @emotion/styled@"^11.10.4" from the root project
npm ERR!       4 more (@mui/material, @mui/styled-engine, @mui/system, @mui/x-date-pickers)
npm ERR!     4 more (@mui/material, @mui/styled-engine, @mui/system, @mui/x-date-pickers)
npm ERR!   20 more (@emotion/styled, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^17.0.0" from @mui/styles@5.11.9
npm ERR! node_modules/@mui/styles
npm ERR!   @mui/styles@"^5.11.7" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: react@17.0.2
npm ERR! node_modules/react
npm ERR!   peer react@"^17.0.0" from @mui/styles@5.11.9
npm ERR!   node_modules/@mui/styles
npm ERR!     @mui/styles@"^5.11.7" 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 /home/varun/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/varun/.npm/_logs/2023-02-23T08_28_03_194Z-debug-0.log

我试着升级我正在使用的npm包的版本,但是仍然有冲突。我需要它们没有错误,因为它很快就要投入生产了。我不想总是使用npm install --force

dfuffjeb

dfuffjeb1#

从npm版本7开始,npm install在遇到冲突的对等依赖项时将失败。
Read more about this behaviour here
您可以通过使用--force--legacy-peer-deps来克服这个问题。
--force为冲突设置不同的对等依赖项版本
--legacy-peer-deps忽略对等依赖项

npm install --legacy-peer-deps

npm install --force

相关问题