安装依赖时报错: npm i 报错问题npm ERR! code ERESOLVEnpm ERR! ERESOLVE could not resolve

PS F:\11-lx\03-xiao\my-project> npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^5.1.0" from [email protected]
npm ERR!   node_modules/copy-webpack-plugin
npm ERR!     peer copy-webpack-plugin@">=5" from @dcloudio/[email protected]
npm ERR!     node_modules/@dcloudio/vue-cli-plugin-uni
npm ERR!       dev @dcloudio/vue-cli-plugin-uni@"^2.0.2-3061420221215001" from the root project
npm ERR! Could not resolve dependency:
npm ERR! cache-loader@"^4.1.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^4.0.0" from [email protected]
npm ERR!   node_modules/cache-loader
npm ERR!     cache-loader@"^4.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! 
npm ERR! For a full report see:
npm ERR! C:\Users\aa\AppData\Local\npm-cache\_logs\2023-05-15T08_17_48_810Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\aa\AppData\Local\npm-cache\_logs\2023-05-15T08_17_48_810Z-debug-0.log

这个问题是安装依赖包的时候少了一些包或者是依赖包丢失导致的

先尝试使用以下文件,删除 node_modules 文件夹和 package-lock.json 文件,

删除package-lock.json 很重要,试了很多次只删除node_modules 都没有效果,所以两个文件同时删除。

然后安装依赖的时候加上 --legacy-peer-deps 这个忽略/修复文件

npm install --legacy-peer-deps

一般这个时候都能成功。

你可能感兴趣的:(npm,webpack,vue.js)