每当我尝试安装一些新的npm包时,npm就会抛出错误



我正在处理这个React项目,从一开始我就得到了这些,但我忽略了它们,并使用npm i package_name -f进行安装,当然可以执行此命令来完成工作,但我想知道是什么原因导致了问题,我想知道如何解决所有这些问题。请不要建议做npm audit fix --force,我已经做过了。

以下是我得到的错误:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: react-currency-format@1.1.0     
npm ERR! Found: react@18.2.0
npm ERR! node_modules/react
npm ERR!   peer react@">=16.8.0" from @emotion/react@11.10.0
npm ERR!   node_modules/@emotion/react
npm ERR!     peer @emotion/react@"^11.0.0-rc.0" from @emotion/styled@11.10.0
npm ERR!     node_modules/@emotion/styled
npm ERR!       peerOptional @emotion/styled@"^11.3.0" from
@mui/material@5.10.2
npm ERR!       node_modules/@mui/material
npm ERR!         peer @mui/material@"^5.0.0" from @mui/icons-material@5.10.2
npm ERR!         node_modules/@mui/icons-material
npm ERR!         1 more (the root project)
npm ERR!       3 more (@mui/styled-engine, @mui/system, the root project)
npm ERR!     peerOptional @emotion/react@"^11.5.0" from @mui/material@5.10.2
npm ERR!     node_modules/@mui/material
npm ERR!       peer @mui/material@"^5.0.0" from @mui/icons-material@5.10.2
npm ERR!       node_modules/@mui/icons-material
npm ERR!         @mui/icons-material@"^5.10.2" from the root project
npm ERR!       1 more (the root project)
npm ERR!     3 more (@mui/styled-engine, @mui/system, the root project)
npm ERR!   peer react@">=16.8.0" from @emotion/styled@11.10.0
npm ERR!   node_modules/@emotion/styled
npm ERR!     peerOptional @emotion/styled@"^11.3.0" from @mui/material@5.10.2
npm ERR!     node_modules/@mui/material
npm ERR!       peer @mui/material@"^5.0.0" from @mui/icons-material@5.10.2
npm ERR!       node_modules/@mui/icons-material
npm ERR!         @mui/icons-material@"^5.10.2" from the root project
npm ERR!       1 more (the root project)
npm ERR!     peerOptional @emotion/styled@"^11.3.0" from @mui/styled-engine@5.10.2
npm ERR!     node_modules/@mui/styled-engine
npm ERR!       @mui/styled-engine@"^5.10.2" from @mui/system@5.10.2
npm ERR!       node_modules/@mui/system
npm ERR!         @mui/system@"^5.10.2" from @mui/material@5.10.2
npm ERR!         node_modules/@mui/material
npm ERR!     2 more (@mui/system, the root project)       
npm ERR!   15 more (@mui/base, @mui/icons-material, @mui/material, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^0.14 || ^15.0.0-rc || ^15.0.0 || ^16.0.0-rc || ^16.0.0 || ^17.0.0" from react-currency-format@1.1.0
npm ERR! node_modules/react-currency-format
npm ERR!   react-currency-format@"^1.1.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: react@17.0.2        
npm ERR! node_modules/react
npm ERR!   peer react@"^0.14 || ^15.0.0-rc || ^15.0.0 || ^16.0.0-rc || ^16.0.0 || ^17.0.0" from react-currency-format@1.1.0
npm ERR!   node_modules/react-currency-format
npm ERR!     react-currency-format@"^1.1.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:UsersnaveenAppDataLocalnpm-cacheeresolve-report.txt for a full report.
npm ERR! While resolving: react-currency-format@1.1.0     
npm ERR! Found: react@18.2.0

这表示您正在使用reactv18.2.0。并且问题是由react-currency-format引起的

Could not resolve dependency:
npm ERR! peer react@"^0.14 || ^15.0.0-rc || ^15.0.0 || ^16.0.0-rc || ^16.0.0 || ^17.0.0" from react-currency-format@1.1.0
npm ERR! node_modules/react-currency-format
npm ERR!   react-currency-format@"^1.1.0" from the root project

此错误消息表示react-currency-formatv1.0仅依赖于reactv15或v16或v17。所以这个版本不支持react的v18。

要解决此问题,请将react降级为v17,或者获取支持reactv18的react-currency-format版本(如果存在(

最新更新