问题再现:

练习Vue的时候,有时候需要安装一些新的工具,这时直接npm install 会出现一些错误

以下以暗转less-loader为例
PS E:\IdeaWorkSpace\WebstormProjects\example-vue2> npm install less less-loader --save-dev
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: example-vue2@0.1.0
npm ERR! Found: webpack@4.46.0
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^4.0.0" from @intervolga/optimize-cssnano-plugin@1.0.6
npm ERR!   node_modules/@intervolga/optimize-cssnano-plugin
npm ERR!     @intervolga/optimize-cssnano-plugin@"^1.0.5" from @vue/cli-service@4.5.15
npm ERR!     node_modules/@vue/cli-service
npm ERR!       peer @vue/cli-service@"^3.0.0 || ^4.0.0-0" from @vue/cli-plugin-babel@4.5.15
npm ERR!       node_modules/@vue/cli-plugin-babel
npm ERR!         dev @vue/cli-plugin-babel@"~4.5.15" from the root project
npm ERR!       4 more (@vue/cli-plugin-eslint, @vue/cli-plugin-router, ...)
npm ERR!   peer webpack@"^4.0.0 || ^5.0.0" from @soda/friendly-errors-webpack-plugin@1.8.1
npm ERR!   node_modules/@soda/friendly-errors-webpack-plugin
npm ERR!     @soda/friendly-errors-webpack-plugin@"^1.7.1" from @vue/cli-service@4.5.15
npm ERR!     node_modules/@vue/cli-service
npm ERR!       peer @vue/cli-service@"^3.0.0 || ^4.0.0-0" from @vue/cli-plugin-babel@4.5.15
npm ERR!       node_modules/@vue/cli-plugin-babel
npm ERR!         dev @vue/cli-plugin-babel@"~4.5.15" from the root project
npm ERR!       4 more (@vue/cli-plugin-eslint, @vue/cli-plugin-router, ...)
npm ERR!   19 more (@vue/cli-plugin-babel, @vue/cli-plugin-eslint, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! dev less-loader@"8" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: webpack@5.70.0
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^5.0.0" from less-loader@8.1.1
npm ERR!   node_modules/less-loader
npm ERR!     dev less-loader@"8" 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 D:\vue\node_cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     D:\vue\node_cache\_logs\2022-03-14T08_32_36_107Z-debug-0.log

原因一般是本地安装的webpack,npm,vue等可能不是最新版本,默认install只会安装最新版本,这时容易出错,如我这个就是因为webpack本地是4,而他要求是5以上的。
那么就寻找本地对应版本来再次尝试

查找less-loader版本
npm view less-loader versions

在这里插入图片描述

下载对应版本

npm install less less-loader@7 --save-dev

只需要在@后加上对应的大版本就可以下载该版本最后的版本

成功

在这里插入图片描述

Logo

前往低代码交流专区

更多推荐