我将开始与另一个开发人员一起开发一个原生react 项目,但在此之前我曾参与过另一个项目,它在Android模拟器上运行时没有出现错误.

我从https://github.com/ismail-benlaredj/ld-vetrinalive-reactnative和Run npm install克隆了该项目,这导致了以下错误:

PS G:\Workspaces\React Native\ld-vetrinalive-reactnative> npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: nativetestapp@0.0.0
npm ERR! Found: react@18.0.0
npm ERR! node_modules/react
npm ERR!   react@"18.0.0" from the root project
npm ERR!   peer react@"*" from native-base@3.4.25
npm ERR!   node_modules/native-base
npm ERR!     native-base@"^3.4.25" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^18.2.0" from react-dom@18.2.0
npm ERR! node_modules/react-dom
npm ERR!   peer react-dom@"*" from native-base@3.4.25
npm ERR!   node_modules/native-base
npm ERR!     native-base@"^3.4.25" 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\DEV-ABDOU\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\DEV-ABDOU\AppData\Local\npm-cache\_logs\2022-12-17T21_35_51_753Z-debug.log

这是前eresolve-report.txt名:

# npm resolution error report

2022-12-17T21:35:51.742Z

While resolving: nativetestapp@0.0.0
Found: react@18.0.0
node_modules/react
  react@"18.0.0" from the root project
  peer react@"*" from native-base@3.4.25
  node_modules/native-base
    native-base@"^3.4.25" from the root project

Could not resolve dependency:
peer react@"^18.2.0" from react-dom@18.2.0
node_modules/react-dom
  peer react-dom@"*" from native-base@3.4.25
  node_modules/native-base
    native-base@"^3.4.25" from the root project

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

Raw JSON explanation object:

{
  "code": "ERESOLVE",
  "current": {
    "name": "react",
    "version": "18.0.0",
    "whileInstalling": {
      "name": "nativetestapp",
      "version": "0.0.0",
      "path": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
    },
    "location": "node_modules/react",
    "isWorkspace": false,
    "dependents": [
      {
        "type": "prod",
        "name": "react",
        "spec": "18.0.0",
        "from": {
          "location": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
        }
      },
      {
        "type": "peer",
        "name": "react",
        "spec": "*",
        "from": {
          "name": "native-base",
          "version": "3.4.25",
          "whileInstalling": {
            "name": "nativetestapp",
            "version": "0.0.0",
            "path": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
          },
          "location": "node_modules/native-base",
          "isWorkspace": false,
          "dependents": [
            {
              "type": "prod",
              "name": "native-base",
              "spec": "^3.4.25",
              "from": {
                "location": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
              }
            }
          ]
        }
      }
    ]
  },
  "currentEdge": {
    "type": "prod",
    "name": "react",
    "spec": "18.0.0",
    "from": {
      "location": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
    }
  },
  "edge": {
    "type": "peer",
    "name": "react",
    "spec": "^18.2.0",
    "error": "INVALID",
    "from": {
      "name": "react-dom",
      "version": "18.2.0",
      "whileInstalling": {
        "name": "nativetestapp",
        "version": "0.0.0",
        "path": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
      },
      "location": "node_modules/react-dom",
      "isWorkspace": false,
      "dependents": [
        {
          "type": "peer",
          "name": "react-dom",
          "spec": "*",
          "from": {
            "name": "native-base",
            "version": "3.4.25",
            "whileInstalling": {
              "name": "nativetestapp",
              "version": "0.0.0",
              "path": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
            },
            "location": "node_modules/native-base",
            "isWorkspace": false,
            "dependents": [
              {
                "type": "prod",
                "name": "native-base",
                "spec": "^3.4.25",
                "from": {
                  "location": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
                }
              }
            ]
          }
        }
      ]
    }
  },
  "strictPeerDeps": false,
  "force": false
}

  • 我不知道我是否应该包括冗长的NPM日志(log)(让我知道).

问题是:

  • 我不知道如何解释错误消息(resolve the peer dependencies)
  • 控制台建议使用标志:--force, or --legacy-peer-deps,风险自负,我对此犹豫不决,因为它说
... to accept an incorrect (and potentially broken) dependency resolution.

这就是我在这里寻求帮助的原因.

关于SOF的类似问题:

React Native app's npm install fails due to conflicting versions of react and react-dom

到目前为止,我try 过的是:

我在网上看到的大多数答案都建议我更新我的全局REACT-Native-CLI,但根据文档here,他们要求您卸载它.

还有一些回答指出一些环境变量没有正确设置,这对我来说不是这样的,因为我的其他项目工作得很好.

推荐答案

尝尝这个.

npm cache verify
rm -rf node_modules
rm package-lock.json
npm i

这将清除NPM缓存并重新构建包-lock.json 和 node 模块

如果不起作用,请让我知道,我会克隆回购并查看.

React-native相关问答推荐

React Native 中的视图与 Flex 不占用相同的高度空间

ios 中节列表中的scrollToLocation 不起作用.在 Android 上,列表滚动回索引 0,但在 ios 上不会发生同样的情况

GetStream:更改消息气泡背景

我们在react钩子中还需要功能性的 setState 方式吗?

React-native 重置数据库

如何在 react-native 中使用 Animated 制作 svg 动画

在 React Native 中从 Modal 打开 Modal

ReactJS 应用多种内联样式

在选项卡更改时react-navigation

如何为我的 React Native Android 应用程序使用 Crashlytics?

检索元素的父项时出错:找不到与给定名称android:TextAppearance.Material.Widget.Button.Colored匹配的资源

如何重置react-native 动画?

error TS2300: Duplicate identifier 'RequestInfo'

当组件在react-native 中重新呈现时,动态不透明度不会改变

React Native:组件卸载时的动画

react native如何访问文件系统?

如何在 react-native 中为在后台杀死的 android 应用程序保持状态

React Native - 如何从推送通知中打开路由

在react-native中调试应用程序崩溃

使用 TouchableWithoutFeedback react-native onPress 不起作用