npm安装依赖时出现Peer Dependencies冲突报错

报错内容

报错原因:由于安装的依赖peerDependency和原先已安装的依赖有冲突

While resolving: [email protected]
Found: [email protected]
node_modules/vue
  peer vue@"^3.2.25" from @vitejs/[email protected]
  node_modules/@vitejs/plugin-vue
    ...

Conflicting peer dependency: [email protected]
node_modules/vue
  peer vue@">= 2.5 < 2.7" from @vue/[email protected]
  node_modules/@vue/composition-api
    peerOptional @vue/composition-api@"^1.4.0" from [email protected]
    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 [email protected] --legacy-peer-deps
@REM node 安装
yarn add [email protected] --legacy-peer-deps

注意:这样安装并不能真正解决问题,在之后安装其他包的时候还是需要加上这个后缀

  • 先在package.json文件中将要安装的依赖加上,然后删除node-modules目录和package-lock.json文件,重新安装依赖,让npm install时去重新匹配依赖

你可能感兴趣的:(npm前端)