由于 ERESOLVE 无法解析依赖关系树,因此无法安装软件包 Pinia
Posted
技术标签:
【中文标题】由于 ERESOLVE 无法解析依赖关系树,因此无法安装软件包 Pinia【英文标题】:Can't install package Pinia because of ERESOLVE unable to resolve dependency tree 【发布时间】:2022-01-04 09:30:38 【问题描述】:我有一个 Vue3 应用程序并想安装包Pinia
操作系统:Win10 和 Pop!_OS 21.04 (Ubuntu) 节点版本:v16.13.0 npm 版本:8.1.0 Vue CLI 版本:4.5.15 Vue 版本:3.0.0创建应用程序后,我运行 npm install pinia
并收到此错误
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: repo@0.0.0-development
npm ERR! Found: vue@3.2.22
npm ERR! node_modules/vue
npm ERR! peerOptional vue@"^2 || ^3.0.0-0" from @vue/babel-preset-app@4.5.15
npm ERR! node_modules/@vue/babel-preset-app
npm ERR! @vue/babel-preset-app@"^4.5.15" 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.0" from the root project
npm ERR! peer vue@"3.2.22" from @vue/server-renderer@3.2.22
npm ERR! node_modules/@vue/server-renderer
npm ERR! @vue/server-renderer@"3.2.22" from vue@3.2.22
npm ERR! 5 more (@vue/test-utils, primevue, vue-jest, vue-router, the root project)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! pinia@"*" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: vue@3.2.23
npm ERR! node_modules/vue
npm ERR! peer vue@">= 2.5 < 3" from @vue/composition-api@1.4.0
npm ERR! node_modules/@vue/composition-api
npm ERR! peerOptional @vue/composition-api@"^1.4.0" from pinia@2.0.4
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.
npm ERR!
npm ERR! See C:\Users\me\AppData\Local\npm-cache\eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\me\AppData\Local\npm-cache\_logs\2021-11-26T09_39_36_434Z-debug.log
生成的日志文件本身就包含这个内容
0 verbose cli [
0 verbose cli 'C:\\Program Files\\nodejs\\node.exe',
0 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
0 verbose cli 'install',
0 verbose cli 'pinia'
0 verbose cli ]
1 info using npm@8.1.0
2 info using node@v16.13.0
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 1ms
5 timing config:load:file:C:\Program Files\nodejs\node_modules\npm\npmrc Completed in 4ms
6 timing config:load:builtin Completed in 4ms
7 timing config:load:cli Completed in 2ms
8 timing config:load:env Completed in 0ms
9 timing config:load:file:C:\Users\me\Repositories\repo\.npmrc Completed in 0ms
10 timing config:load:project Completed in 1ms
11 timing config:load:file:C:\Users\me\.npmrc Completed in 1ms
12 timing config:load:user Completed in 1ms
13 timing config:load:file:C:\Users\me\AppData\Roaming\npm\etc\npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:credentials Completed in 1ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 11ms
19 timing npm:load:configload Completed in 11ms
20 timing npm:load:setTitle Completed in 0ms
21 timing npm:load:setupLog Completed in 1ms
22 timing config:load:flatten Completed in 2ms
23 timing npm:load:cleanupLog Completed in 2ms
24 timing npm:load:configScope Completed in 0ms
25 timing npm:load:projectScope Completed in 1ms
26 timing npm:load Completed in 18ms
27 timing arborist:ctor Completed in 1ms
28 timing idealTree:init Completed in 1304ms
29 timing idealTree:userRequests Completed in 4ms
30 silly idealTree buildDeps
31 silly fetch manifest pinia@*
32 timing arborist:ctor Completed in 0ms
33 http fetch GET 200 https://registry.npmjs.org/pinia 1424ms (cache revalidated)
34 silly fetch manifest @vue/composition-api@^1.4.0
35 http fetch GET 200 https://registry.npmjs.org/@vue%2fcomposition-api 87ms (cache revalidated)
36 silly fetch manifest vue@^3.0.0
37 http fetch GET 200 https://registry.npmjs.org/vue 55ms (cache revalidated)
38 silly fetch manifest vue@>= 2.5 < 3
39 silly fetch manifest typescript@~4.1.5
40 http fetch GET 200 https://registry.npmjs.org/typescript 60ms (cache revalidated)
41 silly fetch manifest typescript@^4.4.4
42 timing idealTree Completed in 2998ms
43 timing command:install Completed in 3012ms
44 verbose stack Error: could not resolve
44 verbose stack at PlaceDep.failPeerConflict (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\place-dep.js:544:25)
44 verbose stack at PlaceDep.place (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\place-dep.js:197:21)
44 verbose stack at new PlaceDep (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\place-dep.js:71:10)
44 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:944:31
44 verbose stack at Array.map (<anonymous>)
44 verbose stack at Arborist.[buildDepStep] (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:944:8)
44 verbose stack at async Arborist.buildIdealTree (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:216:7)
44 verbose stack at async Promise.all (index 1)
44 verbose stack at async Arborist.reify (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:149:5)
44 verbose stack at async Install.install (C:\Program Files\nodejs\node_modules\npm\lib\install.js:170:5)
45 verbose cwd C:\Users\me\Repositories\repo
46 verbose Windows_NT 10.0.19042
47 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "pinia"
48 verbose node v16.13.0
49 verbose npm v8.1.0
50 error code ERESOLVE
51 error ERESOLVE could not resolve
52 error
53 error While resolving: [1mrepo[22m@[1m0.0.0-development[22m
53 error Found: [1mvue[22m@[1m3.2.22[22m[2m[22m
53 error [2mnode_modules/vue[22m
53 error peerOptional [1mvue[22m@"[1m^2 || ^3.0.0-0[22m" from [1m@vue/babel-preset-app[22m@[1m4.5.15[22m[2m[22m
53 error [2mnode_modules/@vue/babel-preset-app[22m
53 error [1m@vue/babel-preset-app[22m@"[1m^4.5.15[22m" from [1m@vue/cli-plugin-babel[22m@[1m4.5.15[22m[2m[22m
53 error [2mnode_modules/@vue/cli-plugin-babel[22m
53 error [33mdev[39m [1m@vue/cli-plugin-babel[22m@"[1m~4.5.0[22m" from the root project
53 error [35mpeer[39m [1mvue[22m@"[1m3.2.22[22m" from [1m@vue/server-renderer[22m@[1m3.2.22[22m[2m[22m
53 error [2mnode_modules/@vue/server-renderer[22m
53 error [1m@vue/server-renderer[22m@"[1m3.2.22[22m" from [1mvue[22m@[1m3.2.22[22m
53 error 5 more (@vue/test-utils, primevue, vue-jest, vue-router, the root project)
53 error
53 error Could not resolve dependency:
53 error [1mpinia[22m@"[1m*[22m" from the root project
53 error
53 error Conflicting peer dependency: [1mvue[22m@[1m3.2.23[22m[2m[22m
53 error [2mnode_modules/vue[22m
53 error [35mpeer[39m [1mvue[22m@"[1m>= 2.5 < 3[22m" from [1m@vue/composition-api[22m@[1m1.4.0[22m[2m[22m
53 error [2mnode_modules/@vue/composition-api[22m
53 error peerOptional [1m@vue/composition-api[22m@"[1m^1.4.0[22m" from [1mpinia[22m@[1m2.0.4[22m[2m[22m
53 error [2mnode_modules/pinia[22m
53 error [1mpinia[22m@"[1m*[22m" from the root project
53 error
53 error Fix the upstream dependency conflict, or retry
53 error this command with --force, or --legacy-peer-deps
53 error to accept an incorrect (and potentially broken) dependency resolution.
53 error
53 error See C:\Users\me\AppData\Local\npm-cache\eresolve-report.txt for a full report.
54 verbose exit 1
有一个未解决的问题https://github.com/posva/pinia/issues/724,如上所述,可以通过插件 (vue add vue-cli-plugin-pinia
) 安装 Pinia,但我不需要插件。
我不确定是否应该通过 npm install pinia --force
或 npm install pinia --legacy-peer-deps
安装 Pinia,因为这似乎很危险。
有人知道怎么解决吗?
这是已安装软件包的列表
"dependencies":
"core-js": "^3.6.5",
"vue": "^3.0.0",
"vue-router": "^4.0.0-0"
,
"devDependencies":
"@types/jest": "^24.0.19",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-e2e-cypress": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-router": "~4.5.0",
"@vue/cli-plugin-typescript": "~4.5.0",
"@vue/cli-plugin-unit-jest": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"@vue/compiler-sfc": "^3.0.0",
"@vue/eslint-config-prettier": "^6.0.0",
"@vue/eslint-config-typescript": "^7.0.0",
"@vue/test-utils": "^2.0.0-0",
"eslint": "^6.7.2",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-vue": "^7.0.0",
"prettier": "^2.2.1",
"typescript": "~4.1.5",
"vue-jest": "^5.0.0-0"
【问题讨论】:
使用--force
并不“危险”。这似乎是目前解决此问题的唯一方法。
【参考方案1】:
我没有直接安装 Pinia,而是安装了the Pinia plugin,这是非官方的,但至少它可以工作:
vue add vue-cli-plugin-pinia
【讨论】:
【参考方案2】:看起来您的问题是您可能已经根据 Vue 2 installation instructions for Pinia 安装了 Pinia,这明确要求您安装额外的 @vue/composition-api 依赖项。
@vue/composition-api 是一个 Vue 2 插件。
它不会在 Vue 3 中运行,这是您正在运行的版本。
所以,转储 @vue/composition-api 依赖项
npm remove @vue/composition-api
你应该准备好了。
【讨论】:
不,我没有这个依赖。我添加了一张图片,显示了我通过 Vue CLI 安装的内容。即使在运行npm remove @vue/composition-api
之后,错误仍然存在。
它可以在您的机器上运行吗?我可以在 Windows 和一些 Linux 发行版上重现它
但是您可以尝试使用 CLI 版本创建一个新的 Vue 项目(请参阅我发布的图片),您应该有相同的 package.json 文件以上是关于由于 ERESOLVE 无法解析依赖关系树,因此无法安装软件包 Pinia的主要内容,如果未能解决你的问题,请参考以下文章
ngx-datatable ERESOLVE 无法解析依赖树