[英]Overriding peer dependency error on npm install
我正在嘗試運行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.
選項 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
或更高版本。
預期的對等依賴版本在錯誤消息中 - 使用語義版本控制。
代替
"react-native-web": "^0.17.1"
到“react-native-web”:“^17.0.1”
看看它是否有效,認為你的 packege.json 不匹配看到錯誤日志
peer react@">=17.0.1" from react-native-web@0.17.1
在包名后使用--legacy-peer-deps
。 作為
npm install your-packages --legacy-peer-deps
這是一個非常常見的錯誤,即使您在使用 expo 時嘗試使用 eas build,或者當您只是執行 npm install 來安裝 npm 依賴項時也是如此。 我通過執行以下操作解決了它:
我在項目根目錄的終端中執行了此操作:
expo doctor
它給了我這個:
Expected package @expo/config-plugins@^5.0.2
Found invalid:
@expo/config-plugins@4.0.6
(for more info, run: npm why @expo/config-plugins)
Some dependencies are incompatible with the installed expo package version:
- expo-status-bar - expected version: ~1.4.2 - actual version installed: 1.2.0
- expo-updates - expected version: ~0.15.6 - actual version installed: 0.11.7
- react - expected version: 18.1.0 - actual version installed: 18.2.0
- react-dom - expected version: 18.1.0 - actual version installed: 17.0.1
- react-native - expected version: 0.70.5 - actual version installed: 0.70.6
- react-native-reanimated - expected version: ~2.12.0 - actual version installed: 2.13.0
- react-native-safe-area-context - expected version: 4.4.1 - actual version installed: 3.3.2
- react-native-screens - expected version: ~3.18.0 - actual version installed: 3.10.2
- react-native-web - expected version: ~0.18.9 - actual version installed: 0.17.1
- react-native-webview - expected version: 11.23.1 - actual version installed: 11.15.0
Your project may not work correctly until you install the correct versions of the packages.
To install the correct versions of these packages, please run: expo doctor --fix-dependencies,
or install individual packages by running expo install [package-name ...]
然后我這樣做了:
expo doctor --fix-dependencies
然后我去這個,沒有更多的錯誤:
Expected package @expo/config-plugins@^5.0.2
Found invalid:
@expo/config-plugins@4.0.6
(for more info, run: npm why @expo/config-plugins)
Some dependencies are incompatible with the installed expo package version:
- expo-status-bar - expected version: ~1.4.2 - actual version installed: 1.2.0
- expo-updates - expected version: ~0.15.6 - actual version installed: 0.11.7
- react - expected version: 18.1.0 - actual version installed: 18.2.0
- react-dom - expected version: 18.1.0 - actual version installed: 17.0.1
- react-native - expected version: 0.70.5 - actual version installed: 0.70.6
- react-native-reanimated - expected version: ~2.12.0 - actual version installed: 2.13.0
- react-native-safe-area-context - expected version: 4.4.1 - actual version installed: 3.3.2
- react-native-screens - expected version: ~3.18.0 - actual version installed: 3.10.2
- react-native-web - expected version: ~0.18.9 - actual version installed: 0.17.1
- react-native-webview - expected version: 11.23.1 - actual version installed: 11.15.0
This command is being executed with the global Expo CLI. Learn more: https://blog.expo.dev/the-new-expo-cli-f4250d8e3421
To use the local CLI instead (recommended in SDK 46 and higher), run:
› npx expo install
Installing 10 SDK 47.0.0 compatible native modules using npm.
> npm install
added 10 packages, removed 97 packages, changed 33 packages, and audited 1216 packages in 2m
57 packages are looking for funding
run `npm fund` for details
7 vulnerabilities (1 low, 5 high, 1 critical)
To address issues that do not require attention, run:
npm audit fix
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.