Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native Can';由于依赖关系,无法升级本机项目_React Native_Npm - Fatal编程技术网

React native Can';由于依赖关系,无法升级本机项目

React native Can';由于依赖关系,无法升级本机项目,react-native,npm,React Native,Npm,我正在尝试将我的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@&quo

我正在尝试将我的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-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@^17.0.1
对于
react是错误的-native@0.63.3
这需要
react@16.13.1
但这是由
npx npm check updates-u
-为什么会生成不兼容的deps树产生的

如果我手动将react版本更改为“^16.0.0”,npm安装将失败,原因是:

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的建议,我手动更新了依赖项,然后我又回到了促使我升级的问题

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! 
还有让我筋疲力尽的事

我有一个来自@react native community/viewpager的组件
,如果它需要peerDep
react@“^16.0”
,为什么它不接受
react@16.13.1
^16.0
意味着比
16.*
更新鲜,不是吗?!当我在上选中
^16.0
时,它会显示我的
16.13.1

解决方法

更新时遇到此问题时:

  • 删除
    node\u模块
    package lock.json
  • npm i
  • npm i
    失败时-删除失败的依赖项
  • 完成
    npm i
    后-手动安装删除的依赖项

  • 我最近经历了这个。。。使用。手动进行每一次更改都很痛苦,但它是有效的

    从日志中:react-native 0.63.3需要react@“16.13.1”,但找到react@“^17.0.1”。只需通过
    npm安装降级您的reactreact@16.13.1
    然后再次尝试
    npm安装。它应该可以正常工作。如果您运行npm过时,您将看到“react”已过时。但是,您不太可能拥有最新版本的所有软件包。

    因此,当我从RN
    0.63.1
    迁移到
    0.64.1
    时,我也遇到了这个问题,因此我通过以下方式解决了这个问题:

  • 步骤运行
    npx react native升级
    对我来说,它更新了
    react
    react native
  • 然后我手动更新了这些依赖项:
  • 您可以使用此工具查看这些命令
    npx对本机升级做出了哪些更改,以及您必须手动执行哪些更改
    

  • 然后运行
    npm install--force
    以手动添加的新依赖项更新
    package lock.json
    。 如果您有使用Jest的测试,那么您还必须调整一些内容,请转到
    Jest.configs.js
    ,并确保这里有
    react native
    @react native
  • 也许你也会对这些模拟有一些问题

    // The old way
    jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
    // Here path was updated
    jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
    
    现在您应该可以开始了,这个示例用于将RN从0.63.1升级到0.64.1,但它也可以为您工作


    p、 我使用的是
    node-v14.15.4
    npm-v7.7.6
    如果您使用的是npmv6,问题可能会少一些

    谢谢,@Anthony,我会试试的
    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');