javascript 覆盖npm安装时的对等依赖关系错误

62lalag4  于 2022-10-30  发布在  Java
关注(0)|答案(3)|浏览(183)

我尝试运行npm install @react-navigation/native @react-navigation/native-stack,但在运行时收到以下错误:

npm WARN ERESOLVE overriding peer dependency
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: react-native-web@0.17.1
npm ERR! Found: react@16.13.1
npm ERR! node_modules/react
npm ERR!   peer react@"^17.0.0" from react-freeze@1.0.0
npm ERR!   node_modules/react-native-screens/node_modules/react-freeze
npm ERR!     react-freeze@"^1.0.0" from react-native-screens@3.13.1
npm ERR!     node_modules/react-native-screens
npm ERR!       peer react-native-screens@">= 3.0.0" from @react-navigation/native-stack@6.6.2
npm ERR!       node_modules/@react-navigation/native-stack
npm ERR!         @react-navigation/native-stack@"*" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@">=17.0.1" from react-native-web@0.17.1
npm ERR! node_modules/react-native-web
npm ERR!   react-native-web@"^0.17.1" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: react@18.2.0
npm ERR! node_modules/react
npm ERR!   peer react@">=17.0.1" from react-native-web@0.17.1
npm ERR!   node_modules/react-native-web
npm ERR!     react-native-web@"^0.17.1" 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/reptar/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/reptar/.npm/_logs/2022-06-15T11_49_30_010Z-debug-0.log

下面是我的package.json文件:

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "axios": "^0.21.4",
    "expo": "~42.0.1",
    "expo-status-bar": "~1.0.4",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",
    "react-native-select-dropdown": "^1.0.9",
    "react-native-web": "^0.17.1"
  },
  "devDependencies": {
    "@babel/core": "^7.9.0"
  },
  "private": true
}

有没有人能指导我如何修复这个问题?这是我在必须安装或修复依赖项/包时最纠结的事情。
================================更新:
当我试图更新react时,我必须同时更新react-dom,否则会得到类似的错误。所以我运行了npm i react@latest react-dom@latest。然后我会尝试再次运行导航安装,并会得到以下错误

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: undefined@undefined
npm ERR! Found: react@18.2.0
npm ERR! node_modules/react
npm ERR!   react@"^18.2.0" from the root project
npm ERR!   peer react@"*" from @react-navigation/native@6.0.10
npm ERR!   node_modules/@react-navigation/native
npm ERR!     @react-navigation/native@"*" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"16.13.1" from react-native@0.63.2
npm ERR! node_modules/react-native
npm ERR!   react-native@"https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz" from the root project
npm ERR!   peer react-native@"*" from @react-navigation/native@6.0.10
npm ERR!   node_modules/@react-navigation/native
npm ERR!     @react-navigation/native@"*" 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.
w8f9ii69

w8f9ii691#

选项1 -忽略上游依赖项,后果自负(根据错误消息):

npm install @react-navigation/native @react-navigation/native-stack --legacy-peer-deps

选项2 -更新react的版本,以满足上游依赖关系(react@"〉=17.0.1”):
npm install react@17.0.1或最新版本npm install react@latest
然后......

npm install @react-navigation/native @react-navigation/native-stack

更新后,从peer react-dom@">=17.0.1" from react-native-web@0.17.1行可以清楚地看到,您应该使用npm install react-dom@17.0.1或更高版本。
预期的对等依赖项版本在错误消息中-使用语义版本控制。

lrl1mhuk

lrl1mhuk2#

替换

"react-native-web": "^0.17.1"

到“react-native-web”:“^17.0.1”
看看它是否工作,认为您的packe.json是mimatched看到错误日志

peer react@">=17.0.1" from react-native-web@0.17.1
f5emj3cl

f5emj3cl3#

在您的软件包名称后面使用--legacy-peer-deps。as

npm install your-packages --legacy-peer-deps

相关问题