【问题标题】:Is using '--force' or '--legacy-peer-deps' would harm in long run?从长远来看,使用“--force”或“--legacy-peer-deps”会有害吗?
【发布时间】:2021-08-02 07:59:56
【问题描述】:

我目前正在做一个 react-native 项目,想安装原生库,但出现以下错误...

npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: demo@0.0.1
npm ERR! Found: react@17.0.2
npm ERR! node_modules/react
npm ERR!   react@"^17.0.1" from the root project
npm ERR!   peer react@"*" from native-base@3.0.6
npm ERR!   node_modules/native-base
npm ERR!     native-base@"3.0.6" from the root project
npm ERR!   1 more (react-dom)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"17.0.1" from react-native@0.64.2
npm ERR! node_modules/react-native
PS C:\Users\Bishal Ghosh\Desktop\React-Native\demo> npm install native-base --save
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: demo@0.0.1
npm ERR! Found: react@17.0.2
npm ERR! node_modules/react
npm ERR!   react@"^17.0.1" from the root project
npm ERR!   peer react@"*" from native-base@3.0.6
npm ERR!   node_modules/native-base
npm ERR!     native-base@"*" from the root project
npm ERR!   1 more (react-dom)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"17.0.1" from react-native@0.64.2
npm ERR! node_modules/react-native
npm ERR!   react-native@"^0.64.2" from the root project
npm ERR!   peer react-native@"*" from native-base@3.0.6
npm ERR!   node_modules/native-base
npm ERR!     native-base@"*" 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\Bishal Ghosh\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\Bishal Ghosh\AppData\Local\npm-cache\_logs\2021-08-02T06_48_53_257Z-debug.log

我尝试通过删除我的 node_modules 文件夹来解决这个问题,但没有奏效。然后,我使用 --legacy-peer-deps 安装,它就安装好了。那么,现在我想知道如果我使用这些标志安装我的依赖项,它会长期运行吗??

【问题讨论】:

    标签: javascript reactjs react-native npm


    【解决方案1】:

    我认为这不会有害,但我不能告诉你这是一个事实。
    我能做的就是告诉我我是如何解决我遇到的类似问题的。

    我假设您使用的是 npm 版本 7.X.X(您可以使用 npm --version 检查它
    如果确实如此,那么这个错误几乎会出现在您尝试安装的每个依赖项上,所以我所做的就是降级回 npm 6。

    为此,您只需在命令行中运行以下命令:

    npm install -g npm@6.14.13
    

    【讨论】:

    • 但是降级我的 npm 版本会限制我利用最新功能.....
    • 哪些是..?更严格的依赖树管理..?好吧,这只是一个建议..您可以继续使用这些解决方法..但请注意,您最终可能会强制安装与依赖关系树无关的东西
    • 强制安装包安全吗?
    • 好吧,您正在强制安装。如果它总是安全的,我认为它是默认设置,没有必要“强制”
    猜你喜欢
    • 2021-05-07
    • 2013-10-30
    • 2022-11-10
    • 2022-11-28
    • 2015-06-04
    • 2021-11-28
    • 2022-11-10
    • 1970-01-01
    • 2021-07-18
    相关资源
    最近更新 更多