簡體   English   中英

由於依賴關系無法升級 React-Native 項目

[英]Can't upgrade React-Native project due dependencies

我正在嘗試將我的 RN 項目從 0.62.2 更新到最新版本(當前為 0.63.3)。 我只是運行npm update並得到錯誤:

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.13.1" from react-native@0.63.3
npm ERR! node_modules/react-native
npm ERR!   react-native@"^0.63.3" 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 update之前,我運行了 npx npx npm-check-updates -u並得到以下信息:

 @react-native-community/netinfo          ^5.9.5  →   ^5.9.9     
 @react-navigation/drawer                 ^5.8.6  →  ^5.11.4     
 @react-navigation/native                 ^5.7.1  →  ^5.8.10     
 @react-navigation/stack                  ^5.7.1  →  ^5.12.8     
 @types/react                           ^16.9.43  →  ^17.0.0     
 amazon-cognito-identity-js               ^3.3.3  →   ^4.5.5     
 aws-amplify                             ^3.0.21  →  ^3.3.10     
 axios                                   ^0.19.2  →  ^0.21.0     
 graphql                                 ^0.11.7  →  ^15.4.0     
 graphql-tag                             ^2.10.4  →  ^2.11.0     
 moment-timezone                         ^0.5.31  →  ^0.5.32     
 react                                  ^16.11.0  →  ^17.0.1     
 react-native                            ^0.62.2  →  ^0.63.3     
 react-native-base64                       0.0.2  →    0.1.0     
 react-native-gesture-handler             ~1.5.0  →   ~1.9.0     
 react-native-reanimated                  ~1.4.0  →  ~1.13.2     
 react-native-safe-area-context           ^0.7.3  →   ^3.1.9     
 react-native-screens             2.0.0-alpha.12  →   2.15.0     
 react-native-simple-crypto              ^0.2.13  →  ^0.2.15     
 react-native-vector-icons                ^6.7.0  →   ^7.1.0     
 react-navigation                         ^4.4.0  →   ^4.4.3     
 @babel/core                               7.8.7  →   7.12.9     
 @babel/runtime                            7.8.7  →   7.12.5     
 babel-jest                               24.9.0  →   26.6.3     
 metro-react-native-babel-preset          0.56.4  →   0.64.0     
 react-test-renderer                      16.9.0  →   17.0.1   

好的,我從錯誤中總結出react-native@0.63.3對於需要react@16.13.1react@^17.0.1是錯誤的,但這是由 npx npx npm-check-updates -u產生的 - 為什么它會導致不兼容的 deps樹?..

如果我將手動反應版本更改為“^16.0.0”, npm install失敗:

npm ERR! Found: react@16.14.0
npm ERR! node_modules/react
npm ERR!   react@"^16.0.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"16.13.1" from react-native@0.63.3
npm ERR! node_modules/react-native
npm ERR!   react-native@"^0.63.3" from the root project

為什么是“react@16.14.0”?? 從哪里?

我只是不明白這一切是如何運作的。請建議。

我目前的package.json

{
  "name": "Proj",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@react-native-community/masked-view": "^0.1.10",
    "@react-native-community/netinfo": "^5.9.9",
    "@react-navigation/drawer": "^5.11.4",
    "@react-navigation/native": "^5.8.10",
    "@react-navigation/stack": "^5.12.8",
    "@types/react": "^17.0.0",
    "amazon-cognito-identity-js": "^4.5.5",
    "aws-amplify": "^3.3.10",
    "axios": "^0.21.0",
    "graphql": "^15.4.0",
    "graphql-tag": "^2.11.0",
    "i18n-js": "^3.8.0",
    "moment-timezone": "^0.5.32",
    "react": "^16.0.0",
    "react-native": "^0.63.3",
    "react-native-avatar-social": "0.0.3",
    "react-native-base64": "0.1.0",
    "react-native-gesture-handler": "~1.9.0",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-localize": "^2.0.1",
    "react-native-reanimated": "~1.13.2",
    "react-native-safe-area-context": "^3.1.9",
    "react-native-screens": "2.15.0",
    "react-native-simple-crypto": "^0.2.15",
    "react-native-tab-view": "^2.15.2",
    "react-native-tab-view-viewpager-adapter": "^1.1.0",
    "react-native-uuid-generator": "^6.1.1",
    "react-native-vector-icons": "^7.1.0",
    "react-native-video": "^4.4.5",
    "react-native-viewpager": "^0.2.13",
    "react-native-zeroconf": "github:atlascoder/react-native-zeroconf",
    "react-navigation": "^4.4.3",
    "rn-fetch-blob": "^0.12.0"
  },
  "devDependencies": {
    "@babel/core": "7.12.9",
    "@babel/runtime": "7.12.5",
    "babel-jest": "26.6.3",
    "metro-react-native-babel-preset": "0.64.0",
    "react-test-renderer": "17.0.1"
  },
  "rnpm": {
    "assets": [
      "./assets/fonts/"
    ]
  }
}

更新

根據@anthony-marino 的建議,我通過update helper進行了手動依賴項更新,然后我回到了讓我升級的問題!

npm ERR! Found: react@16.13.1
npm ERR! node_modules/react
npm ERR!   react@"16.13.1" from the root project
npm ERR!   peer react@"^16.0" from @react-native-community/viewpager@4.2.1
npm ERR!   node_modules/@react-native-community/viewpager
npm ERR!     peer @react-native-community/viewpager@"*" from react-native-tab-view-viewpager-adapter@1.1.0
npm ERR!     node_modules/react-native-tab-view-viewpager-adapter
npm ERR!       react-native-tab-view-viewpager-adapter@"^1.1.0" from the root project
npm ERR!   15 more (@react-navigation/core, @react-navigation/drawer, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"16.11.0" from react-native-zeroconf@0.12.3
npm ERR! node_modules/react-native-zeroconf
npm ERR!   react-native-zeroconf@"github:atlascoder/react-native-zeroconf" from the root project
npm ERR! 

而讓我失望的東西..

我有一個from @react-native-community/viewpager的組件,為什么它需要 peerDep react@"^16.0" - 為什么它不接受react@16.13.1 ^16.0意味着比16.*更新鮮,不是嗎?! 當我在npm semver 計算器上檢查^16.0時 - 它顯示16.13.1適合..

解決方法

在更新時遇到這個麻煩:

  1. 刪除node_modulespackage-lock.json
  2. npm i
  3. npm i失敗時 - 刪除失敗的依賴項
  4. npm i完成后 - 手動安裝刪除的依賴項

我最近經歷了這個......使用升級助手 手動進行每次更改都很痛苦,但它確實有效!

從您的日志中:react-native 0.63.3 需要 react@"16.13.1",但發現 react@"^17.0.1"。 只需通過npm install react@16.13.1降級您的反應,然后再次嘗試npm install 它應該可以正常工作。 如果你運行 npm outdated 你會看到“react”已經過時了。 但是您不太可能將所有軟件包都安裝在最新版本中。

所以當我從 RN 0.63.1遷移到0.64.1時,我也遇到了這個問題,所以我以這種方式解決了它:

  1. 步驟運行npx react-native upgrade對我來說它更新了reactreact-native
  2. 然后我手動更新了這些依賴項:
"@babel/core": "^7.12.9",
"@babel/runtime": "^7.12.5",
"@react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.6.3",
"eslint": "7.14.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.64.0",
"react-test-renderer": "17.0.1"

you could use this tool to see what changes did these command npx react-native upgrade and what changes you have to do it manualy https://react-native-community.github.io/upgrade-helper/?from=0.63.1&to=0.64 .1

  1. 然后運行npm install --force以使用您手動添加的新依賴項更新package-lock.json 如果您可能對 Jest 進行了測試,那么您還必須將 go 調整為jest.configs.js並確保您在這里有react-native@react-native
transformIgnorePatterns: [
    'node_modules/(?!(jest-)?react-native|@react-native|@react-native-community)',
  ],

可能你也會對這些模擬有一些問題

// The old way
jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
// Here path was updated
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');

現在你應該對 go 很好,這個例子是為了將 RN 從 0.63.1 升級到 0.64.1,但它也可以為你工作。

ps 我正在使用node -v 14.15.4npm -v 7.7.6如果你使用 npm v6,你可能會遇到更少的問題

這解決了我的問題。

npm install @react-native-community/masked-view --force

我不得不使用:

npm i --legacy-peer-deps

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM