npm安装依赖时出现Peer Dependencies冲突报错
报错内容
报错原因:由于安装的依赖peerDependency和原先已安装的依赖有冲突
While resolving: uni-preset-vue@0.0.0
Found: vue@3.2.47
node_modules/vue
peer vue@"^3.2.25" from @vitejs/plugin-vue@4.3.4
node_modules/@vitejs/plugin-vue
...
Conflicting peer dependency: vue@3.3.4
node_modules/vue
peer vue@">= 2.5 < 2.7" from @vue/composition-api@1.7.2
node_modules/@vue/composition-api
peerOptional @vue/composition-api@"^1.4.0" from pinia@2.0.34
node_modules/pinia
pinia@"2.0.34" from the root project
Fix the upstream dependency conflict, or retry
this command with --force or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.
解决方案
- 在安装命令后面加上--force 或者--legacy-peer-deps,让它忽略这个冲突
@REM npm 安装
npm i pinia@2.0 --legacy-peer-deps
@REM node 安装
yarn add pinia@2.0 --legacy-peer-deps
注意:这样安装并不能真正解决问题,在之后安装其他包的时候还是需要加上这个后缀
- 先在package.json文件中将要安装的依赖加上,然后删除node-modules目录和package-lock.json文件,重新安装依赖,让npm install时去重新匹配依赖