无法解析依赖树 Reactjs
Posted
技术标签:
【中文标题】无法解析依赖树 Reactjs【英文标题】:Unable to resolve dependency tree Reactjs 【发布时间】:2021-02-19 10:10:36 【问题描述】:我正在尝试在我当前的项目中安装 react-tinder-card。所以我正在尝试安装 react-tinder-card 但在我使用命令之后
npm install --save react-tinder-card
我在控制台中只能看到:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: tinder-clone@0.1.0
npm ERR! Found: react@17.0.1
npm ERR! node_modules/react
npm ERR! react@"^17.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.0" from react-tinder-card@1.3.1
npm ERR! node_modules/react-tinder-card
npm ERR! react-tinder-card@"*" 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 /home/nero/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/nero/.npm/_logs/2020-11-06T16_36_39_957Z-debug.log
当我打开 debug.log 文件时,我发现:
0 verbose cli [
0 verbose cli '/usr/bin/node',
0 verbose cli '/usr/bin/npm',
0 verbose cli 'install',
0 verbose cli '--save',
0 verbose cli 'react-tinder-card'
0 verbose cli ]
1 info using npm@7.0.3
2 info using node@v15.0.1
3 timing config:load:defaults Completed in 3ms
4 timing config:load:file:/usr/lib/node_modules/npm/npmrc Completed in 0ms
5 timing config:load:builtin Completed in 1ms
6 timing config:load:cli Completed in 3ms
7 timing config:load:env Completed in 1ms
8 timing config:load:file:/home/nero/Documents/MERN/tinder-clone/.npmrc Completed in 1ms
9 timing config:load:project Completed in 2ms
10 timing config:load:file:/home/nero/.npmrc Completed in 0ms
11 timing config:load:user Completed in 0ms
12 timing config:load:file:/usr/etc/npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:setUserAgent Completed in 0ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 12ms
19 verbose npm-session b46c4469ef66a9f2
20 timing npm:load Completed in 19ms
21 timing arborist:ctor Completed in 0ms
22 timing idealTree:init Completed in 1413ms
23 timing idealTree:userRequests Completed in 3ms
24 silly idealTree buildDeps
25 silly fetch manifest react-tinder-card@*
26 http fetch GET 200 https://registry.npmjs.org/react-tinder-card 188ms (from cache)
27 silly fetch manifest react@^17.0.1
28 timing arborist:ctor Completed in 0ms
29 http fetch GET 304 https://registry.npmjs.org/react 1196ms (from cache)
30 timing idealTree Completed in 2812ms
31 timing command:install Completed in 2815ms
32 verbose stack Error: unable to resolve dependency tree
32 verbose stack at Arborist.[failPeerConflict] (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1011:25)
32 verbose stack at Arborist.[loadPeerSet] (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:991:36)
32 verbose stack at async Arborist.[buildDepStep] (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:760:11)
32 verbose stack at async Arborist.buildIdealTree (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:202:7)
32 verbose stack at async Promise.all (index 1)
32 verbose stack at async Arborist.reify (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:121:5)
32 verbose stack at async install (/usr/lib/node_modules/npm/lib/install.js:40:5)
33 verbose cwd /home/nero/Documents/MERN/tinder-clone
34 verbose Linux 5.4.0-52-generic
35 verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "--save" "react-tinder-card"
36 verbose node v15.0.1
37 verbose npm v7.0.3
38 error code ERESOLVE
39 error ERESOLVE unable to resolve dependency tree
40 error
41 error While resolving: [1mtinder-clone[22m@[1m0.1.0[22m
41 error Found: [1mreact[22m@[1m17.0.1[22m[2m[22m
41 error [2mnode_modules/react[22m
41 error [1mreact[22m@"[1m^17.0.1[22m" from the root project
41 error
41 error Could not resolve dependency:
41 error [35mpeer[39m [1mreact[22m@"[1m^16.8.0[22m" from [1mreact-tinder-card[22m@[1m1.3.1[22m[2m[22m
41 error [2mnode_modules/react-tinder-card[22m
41 error [1mreact-tinder-card[22m@"[1m*[22m" from the root project
41 error
41 error Fix the upstream dependency conflict, or retry
41 error this command with --force, or --legacy-peer-deps
41 error to accept an incorrect (and potentially broken) dependency resolution.
41 error
41 error See /home/nero/.npm/eresolve-report.txt for a full report.
42 verbose exit 1
我不明白那是什么意思。请帮我找到解决方案。任何形式的帮助将不胜感激。 提前谢谢你。
【问题讨论】:
嗨苏尼尔!我刚刚在这里发布了一个类似问题的答案:***.com/questions/64701308/…。你所面临的问题的核心是完全一样的,只是细节不同。这个答案应该会引导您朝着正确的方向前进。 感谢@Avius。 【参考方案1】:$ npm install --save react-tinder-card --legacy-peer-deps
【讨论】:
这个命令到底会做什么?请为其他用户解释。 我发现@Arosha 的回答更有帮助,该软件包将安装 --legacy 标志,但该模块不起作用。降级到 npm 6 更容易【参考方案2】:此错误来自 npm 7.x 版。
请使用--legacy-peer-deps
选项重试。
【讨论】:
来源:blog.npmjs.org/post/626173315965468672/… 检查对等依赖部分。【参考方案3】:这个错误基本上说的是它的对等依赖项中的react-tinder-card@1.3.1
有react@"^16.8.0"
。所以它需要那个版本的 react 才能正常运行。在您的tinder-clone@0.1.0
应用程序中,您当前拥有react@17.0.1
。
这个问题可以手动解决,只需安装react-tinder-card@1.3.1
需要的react版本react@"^16.8.0"
,所以你需要降级你的版本来运行这个包。
--legacy-peer-deps
标志是在npm
的 v7 中引入的,作为绕过 peerDependency 自动安装的一种方式;它告诉 NPM 忽略对等部门并继续安装。这可能会导致一些不良行为,我不建议这样做。
【讨论】:
【参考方案4】:降级到 npm v6。它应该可以解决问题。
npm install -g npm@6
【讨论】:
【参考方案5】:https://www.apollographql.com/docs/react/migrating/apollo-client-3-migration/
react-apollo 包已被弃用,现在可以从@apollo/client 直接访问上述每个包提供的功能:
@apollo/react-hooks -> now available directly from @apollo/client
@apollo/react-components -> now available from @apollo/client/react/components
@apollo/react-hoc -> now available from @apollo/client/react/hoc
@apollo/react-s-s-r -> now available from @apollo/client/react/s-s-r
@apollo/react-testing -> now available from @apollo/client/testing
【讨论】:
【参考方案6】:当您尝试克隆一个很久以前构建的项目时会发生这种情况,并且项目依赖项已转移到较新的版本。
只需运行下面的代码。每次都对我有用。您还应该看到这个错误的解决方案。
npm install --legacy-peer-deps
【讨论】:
【参考方案7】:我在上面遇到了同样的错误。我安装了 npm v6.7。我重新安装了 Netlify CMS 和 Gatsby:
npm install netlify-cms-app@2.9 gatsby-plugin-netlify-cms@^4.0.0
除了 favicon.ico 文件外,我在静态文件夹下没有任何内容。没有 admin 文件夹,也没有 .yml 文件。
【讨论】:
【参考方案8】:升级到 npm v8。它应该可以解决问题。
npm install -g npm@8
【讨论】:
v8.3.0同样报错,需要使用--legacy-peer-deps
标志以上是关于无法解析依赖树 Reactjs的主要内容,如果未能解决你的问题,请参考以下文章