我遇到了一个似乎无法解决的问题。
我试图在项目中更新 webpack 和 webpack-cli,但不断收到如下错误:
npm install webpack@latest --save-dev
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/webpack-cli
npm ERR! dev webpack-cli@"^5.1.4" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer webpack-cli@"4.x.x" from @webpack-cli/[email protected]
npm ERR! node_modules/@webpack-cli/init
npm ERR! dev @webpack-cli/init@"^1.1.3" 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!
npm ERR! For a full report see:
npm ERR! C:\Users\blah.blah\AppData\Local\npm-cache\_logs\2023-09- 25T23_54_32_583Z-eresolve-report.txt
我已完成以下操作:
rm -rf node_modules package-lock.json
npm cache clear --force
我尝试使用以下命令再次安装 webpack:
npm install webpack@latest --save-dev
我也遇到同样的错误。
我检查了node和npm的版本,发现它们已经过时了。我更新了它们,节点是 v18.18.0,npm 是 10.1.0
如果我将标志
--legacy-peer-deps
添加到每个命令,我就可以让它工作。然而,我不应该这样做。
webpack有问题吗?我的系统是否做错了什么或损坏/配置错误?
尝试运行以下命令,
npm audit --fix