npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree

413 阅读1分钟

一、报错

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: cloud-music-react@0.1.0
npm ERR! Found: react-scripts@5.0.1
npm ERR!   react-scripts@"5.0.1" from the root project
npm ERR! 
npm ERR! peer react-scripts@"^4.0.0" from @craco/craco@6.4.3
npm ERR! node_modules/@craco/craco
npm ERR!   @craco/craco@"*" 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\15195\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\15195\AppData\Local\npm-cache\_logs\2022-05-25T15_38_55_580Z-debug-0.log

二、原因

解析依赖树失败,是因为npm@7更加严格。通常,最简单的解决方法是将--legacy-peer-deps标志传递给npm(e.g.,npm i --legacy-peer-deps),或者使用npm@6。

三、解决方法

npx -p npm@6 npm i @craco/craco  --legacy-peer-deps

这样我的@craco/craco依赖就可以成功注入了