简体   繁体   English

为 Vue3 安装 Pinia 导致 ERESOLVE 无法解析依赖树

[英]Installing Pinia for Vue3 throws ERESOLVE unable to resolve dependency tree

I want to install the package Pinia for my Vue3 app.我想为我的 Vue3 应用程序安装 Pania 包。 I run these commands:我运行这些命令:

vue create foo

# select default Vue 3

cd foo

npm install pinia

Unfortunately I get this error不幸的是我收到这个错误

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: foo@0.1.0
npm ERR! Found: vue@3.2.20
npm ERR! node_modules/vue
npm ERR!   vue@"^3.0.0" from the root project
npm ERR!   peer vue@"^2.6.14 || ^3.2.0" from pinia@2.0.0-rc.13
npm ERR!   node_modules/pinia
npm ERR!     pinia@"*" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer vue@">= 2.5 < 3" from @vue/composition-api@1.2.4
npm ERR! node_modules/@vue/composition-api
npm ERR!   peerOptional @vue/composition-api@"^1.2.4" from pinia@2.0.0-rc.13
npm ERR!   node_modules/pinia
npm ERR!     pinia@"*" 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.

I'm using我正在使用

  • Pop!_OS 21.04 (Ubuntu)流行!_OS 21.04 (Ubuntu)
  • node v14.18.1节点 v14.18.1
  • npm v7.5.2 npm v7.5.2
  • Vue CLI v4.5.13 Vue CLI v4.5.13

It might be worth to note that I installed Node/npm LTS (v14.x) via可能值得注意的是,我通过以下方式安装了 Node/npm LTS (v14.x)

https://github.com/nodesource/distributions/blob/master/README.md#debian-and-ubuntu-based-distributions https://github.com/nodesource/distributions/blob/master/README.md#debian-and-ubuntu-based-distributions

I don't know why but it's possible to install Pinia via plugin我不知道为什么,但可以通过插件安装 Pinia

https://github.com/wobsoriano/vue-cli-plugin-pinia https://github.com/wobsoriano/vue-cli-plugin-pinia

So running所以跑步

vue add vue-cli-plugin-pinia

works for me ...对我有用...

Does someone know how to fix it without the need of the plugin?有人知道如何在不需要插件的情况下修复它吗?

Simply change version of vue to less than 3.2.只需将 vue 的版本更改为小于 3.2。

vue@"^3.0.0" from the root project npm ERR! peer vue@"^2.6.14 || ^3.2.0" from pinia@2.0.0-rc.13

This line basically says that pinia only supports vue up to 3.2 at the moment.这条线基本上是说 pinia 目前只支持 vue 到 3.2。

To solve it run:要解决它,请运行:

npm i vue@3.2.0

This will put vue in a version that is still supported by pinia.这将使 vue 处于 pinia 仍支持的版本中。

This will most probably change in the future, but since pinia is in alpha stage, there are still some bugs present.这在未来很可能会改变,但由于 pinia 处于 alpha 阶段,仍然存在一些错误。 I had the opportunity to try it in a project, would not take it to live yet, but the preview of what vuex 5 will be, looks awesome.我有机会在一个项目中尝试它,还不会将其投入使用,但是 vuex 5 的预览版看起来很棒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM