"ERESOLVE 无法解析依赖树" 在安装 npm react-facebook-login 时。

72

尝试在我的 React 应用中安装 npm react-facebook-login,但我一直遇到依赖错误?听起来很可怕,我不想强制安装可能会在将来出问题的东西。作为 JavaScript 的新手,我应该如何继续?

我已经尝试清除我的 npm 缓存、删除节点模块并重新安装它们,然而我仍然得到这个错误。

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: buckets@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.0.0" from react-facebook-login@4.1.1
npm ERR! node_modules/react-facebook-login
npm ERR!   react-facebook-login@"*" 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/user/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2021-01-03T12_23_40_000Z-debug.log

调试日志:

0 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'install', 'react-facebook-login' ]
1 info using npm@7.0.15
2 info using node@v15.4.0
3 timing config:load:defaults Completed in 4ms
4 timing config:load:file:/usr/lib/node_modules/npm/npmrc Completed in 12ms
5 timing config:load:builtin Completed in 12ms
6 timing config:load:cli Completed in 1ms
7 timing config:load:env Completed in 1ms
8 timing config:load:file:/home/user/app/frontend/buckets/.npmrc Completed in 0ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:/home/user/.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 1ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 21ms
19 verbose npm-session a80715ea0624d48b
20 timing npm:load Completed in 30ms
21 timing arborist:ctor Completed in 1ms
22 timing idealTree:init Completed in 1531ms
23 timing idealTree:userRequests Completed in 4ms
24 silly idealTree buildDeps
25 silly fetch manifest react-facebook-login@*
26 http fetch GET 200 https://registry.npmjs.org/react-facebook-login 2249ms
27 silly fetch manifest react@^17.0.1
28 http fetch GET 200 https://registry.npmjs.org/react 142ms
29 timing idealTree Completed in 3940ms
30 timing command:install Completed in 3944ms
31 verbose stack Error: unable to resolve dependency tree
31 verbose stack     at Arborist.[failPeerConflict] (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1045:25)
31 verbose stack     at Arborist.[loadPeerSet] (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1025:36)
31 verbose stack     at async Arborist.[buildDepStep] (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:781:11)
31 verbose stack     at async Arborist.buildIdealTree (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:209:7)
31 verbose stack     at async Promise.all (index 1)
31 verbose stack     at async Arborist.reify (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:122:5)
31 verbose stack     at async install (/usr/lib/node_modules/npm/lib/install.js:39:3)
32 verbose cwd /home/user/app/frontend/buckets
33 verbose Linux 5.4.0-58-generic
34 verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "react-facebook-login"
35 verbose node v15.4.0
36 verbose npm  v7.0.15
37 error code ERESOLVE
38 error ERESOLVE unable to resolve dependency tree
39 error
40 error While resolving: [1mbuckets[22m@[1m0.1.0[22m
40 error Found: [1mreact[22m@[1m17.0.1[22m[2m[22m
40 error [2mnode_modules/react[22m
40 error   [1mreact[22m@"[1m^17.0.1[22m" from the root project
40 error
40 error Could not resolve dependency:
40 error [35mpeer[39m [1mreact[22m@"[1m^16.0.0[22m" from [1mreact-facebook-login[22m@[1m4.1.1[22m[2m[22m
40 error [2mnode_modules/react-facebook-login[22m
40 error   [1mreact-facebook-login[22m@"[1m*[22m" from the root project
40 error
40 error Fix the upstream dependency conflict, or retry
40 error this command with --force, or --legacy-peer-deps
40 error to accept an incorrect (and potentially broken) dependency resolution.
40 error
40 error See /home/user/.npm/eresolve-report.txt for a full report.
41 verbose exit 1


如何在不引起任何未来问题的情况下克服这个困境?感谢您的帮助。
17个回答

163

这个错误来自npm的7.x版本。请尝试添加--legacy-peer-deps选项再次尝试:

这个错误来自npm的7.x版本。请尝试添加--legacy-peer-deps选项再次尝试:

npm install react-facebook-login --legacy-peer-deps

4
在命令末尾加上“--legacy-peer-deps”对我有效。 - RohitAneja
1
谢谢,这对我有用。在安装npm i simplebar-react包时,我遇到了“ERESOLVE”错误。所以我是这样安装的 - npm i simplebar-react --legacy-peer-deps - aish
2
Node 18.x也出现了同样的情况。谢谢! - steve
npm 版本 8.18.0 仍然存在此错误。 - Cris69
这似乎解决了问题,但有人能解释一下为什么吗?使用--legacy-peer-deps会有什么后果吗? - undefined
通过找到另一个帖子,我自己回答了我的问题:https://stackoverflow.com/questions/66239691/what-does-npm-install-legacy-peer-deps-do-exactly-when-is-it-recommended-wh - undefined

12

由于 npm install 无法正常工作,我尝试了以下方法:

yarn install

它有效!

谢谢


8
我也遇到了这个问题,我尝试运行我的React.js应用程序。
我通过运行 npm install --legacy-peer-deps 解决了这个问题。
然后它正常启动了。

6

在最后使用--force或--legacy-peer-deps

例如:

npm install --force

或者
npm install --legacy-peer-deps

1
在 Azure Pipeline 上怎么做? - Sunil Garg

4
升级npm从6到7后,我的代码出现了下面的错误:

npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree

...

npm ERR! Fix the upstream dependency conflict, or retry this command with --force, or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution.

我尝试使用--legacy-peer-deps--force来解决问题,但结果只生成了无用的包。于是我尝试删除node_modulespackage-lock.json并重新安装使用yarn install,这样生成了一个yarn.lock文件和新的package-lock.json,随后在后续的npm运行中发现它们可以正常工作。
注:此方法是在npm 7能够正常工作之前的临时解决方法。之后,我将删除yarn.lock、package-lock.json和node_modules,并使用npm重新生成文件。
rm -rf node_modules
rm package-lock.json 
yarn install 
# generates a yarn.lock file and a new package-lock.json

# continue with npm 
npm start

3

这帮助我解决了这个错误

npm install --f

或者使用

npm install --legacy-peer-deps

2

尝试运行

npm update

如果错误是由于 Firebase 包版本过时与其同级冲突导致,请尤其注意此步骤。按照@snehal建议的方式解决了我的问题。


2

在运行命令时,只需添加--legacy-peer-deps即可。

对于我来说,命令是:

npm install @reduxjs/toolkit react-redux

然后我添加了

npm install @reduxjs/toolkit react-redux --legacy-peer-deps

然后,瞬间就可以运行了。


2

您可以使用以下内容:

npm install angular-google-charts --legacy-peer-deps

或者像这样,如果你想要保存:

npm install --save angular-google-charts --legacy-peer-deps

1

在使用人脸检测应用程序时,我遇到了这个错误,我需要使用react-native-camera来捕获图像。

虽然我的包与这个StackOverflow问题不同,但错误的情况是相同的。

所以,解决方法是我在npm install中添加了-legacy-peer-deps,像这样:

npm install @react-native-community/image-editor --save -legacy-peer-deps

这解决了我的问题。希望对你有帮助。

编码愉快!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接