在npm安装vue-router报错npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve

2022-10-26 17:35:31 浏览数 (2)

运行安装命令:

代码语言:javascript复制
npm install vue-router@next -S

报错信息如下:

代码语言:javascript复制
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: day5-demo@0.0.0
npm ERR! Found: vue@3.0.2
npm ERR! node_modules/vue
npm ERR!   peer vue@"3.0.2" from @vue/compiler-sfc@3.0.2
npm ERR!   node_modules/@vue/compiler-sfc
npm ERR!     peer @vue/compiler-sfc@"*" from rollup-plugin-vue@6.0.0-beta.10
npm ERR!     node_modules/rollup-plugin-vue
npm ERR!       rollup-plugin-vue@"^6.0.0-beta.10" from vite@1.0.0-rc.6
npm ERR!       node_modules/vite
npm ERR!         dev vite@"^1.0.0-rc.1" from the root project
npm ERR!     @vue/compiler-sfc@"^3.0.0-rc.10" from vite@1.0.0-rc.6
npm ERR!     node_modules/vite
npm ERR!       dev vite@"^1.0.0-rc.1" from the root project
npm ERR!     1 more (the root project)
npm ERR!   vue@"^3.0.0-rc.10" from vite@1.0.0-rc.6
npm ERR!   node_modules/vite
npm ERR!     dev vite@"^1.0.0-rc.1" from the root project
npm ERR!   1 more (the root project)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! vue-router@"4.0.13" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: vue@3.2.41
npm ERR!   peer vue@"^3.2.0" from vue-router@4.0.13
npm ERR!   node_modules/vue-router
npm ERR!     vue-router@"4.0.13" 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:UserszeyiAppDataLocalnpm-cacheeresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:

查阅半天,发现原因应该是在安装过程中缺少了依赖,因为刚开始安装了一小段。但更多的可能是npm版本的问题。

大部分的解决方法:

根据错误提示,在命令行中加入–legacy-peer-deps,由于vue与vue-router版本兼容的问题,需要在安装语句后加入需要下载vue-router版本,不然会下载最新的vue-router版本。

代码语言:javascript复制
npm install --legacy-peer-deps vue-router@4.0.13

也有可能因为是你要下载的router版本过高,如果下载版本过高,在启动项目时会报错,可以下载低版本的vue-router

代码语言:javascript复制
npm install vue-router@3.1.3 --save-dev

最后在package.json文件中查看是否下载成功

我的博客即将同步至腾讯云开发者社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=363o1yq3ftc0c

0 人点赞