1. 程式人生 > 其它 >less裝不上,報npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree

less裝不上,報npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree

安裝less報錯:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: [email protected]
npm ERR! node_modules/webpack
npm ERR! dev webpack@"4.41.5" from the root project
npm ERR! peer webpack@">=2" from [email protected]
npm ERR! node_modules/babel-loader
npm ERR! dev babel-loader@"^8.0.0" from the root project
npm ERR! 2 more (copy-webpack-plugin, css-loader)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! dev mini-css-extract-plugin@"^0.9.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/webpack
npm ERR! peer webpack@"^4.4.0" from [email protected]
npm ERR! node_modules/mini-css-extract-plugin
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.

是因為

ERESOLVE與npm@7有關的問題很常見,因為npm7.x對某些事情比npm6.x更嚴格。通常,最簡單的解決方法是將--legacy-peer-deps標誌傳遞給npm(e.g.,npm i --legacy-peer-deps),或者使用npm@6。

如果這不能立即起作用,也許可以先刪除node_modules和package-lock.json。它們將被重新建立

解決方案

降級npm到6版本或使用npx指定npm的版本

降版本執行 npx -p npm@6 npm i --legacy-peer-deps(本人是用此方法解決的)