开发者问题收集

Aws-amplify 无法与 react-native 和 expo 版本 36.0.0 配合使用

2020-03-17
2136

我目前正在使用 expoSdk 开发一个 react-native-app,它应该在 web、ios 和 android 上运行。到目前为止,最具挑战性的部分是设置导航,我终于做到了。现在我将 amplify 添加到我的项目中,但无论何时在任何移动设备上运行它,项目都会停止工作,但在 web 上运行良好。我收到的错误是

NetInfo has been removed from React Native

经过多次反复试验,我发现错误来自 aws-amplify,因为它似乎仍在使用 reac-native-community/netinfo 运行。只有当我从 amplify 导入某些内容时才会出现错误。我在

node_modules\@aws-amplify\core\lib\Util\Reachability.native.js

Deo 中发现了这个问题,有人知道我该如何解决这个问题吗?

如果需要的话,这是我的 package.json

  "dependencies": {
    "@expo/vector-icons": "~10.0.0",
    "aws-amplify": "^2.2.6",
    "@react-native-community/masked-view": "0.1.5",
    "@react-navigation/bottom-tabs": "^5.0.0",
    "@react-navigation/drawer": "^5.2.0",
    "@react-navigation/native": "^5.0.0",
    "@react-navigation/stack": "^5.0.0",
    "@react-navigation/web": "~1.0.0-alpha.9",
    "expo": "~36.0.0",
    "expo-asset": "~8.0.0",
    "expo-constants": "~8.0.0",
    "expo-font": "~8.0.0",
    "expo-web-browser": "~8.0.0",
    "react": "~16.9.0",
    "react-dom": "~16.9.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",
    "react-native-gesture-handler": "~1.5.0",
    "react-native-reanimated": "^1.7.0",
    "react-native-safe-area-context": "0.6.0",
    "react-native-screens": "2.0.0-alpha.12",
    "react-native-web": "~0.11.7",
    "react-spring": "^8.0.27",
    "styled-components": "^5.0.1",
    "@aws-amplify/api": "^2.1.6",
    "@aws-amplify/pubsub": "^2.1.7",
    "@expo/samples": "^3.0.3",
    "apollo-boost": "^0.4.3",
    "apollo-cache-inmemory": "^1.6.2",
    "apollo-client": "^2.6.3",
    "apollo-link-http": "^1.5.15",
    "aws-amplify-react-native": "^3.2.2",
    "aws-appsync": "^1.7.0",
    "aws-appsync-react": "^1.2.5",
    "expo-av": "~8.0.0",
    "expo-camera": "~8.0.0",
    "expo-file-system": "~8.0.0",
    "expo-image-picker": "~8.0.1",
    "expo-permissions": "~8.0.0",
    "graphql-tag": "^2.10.1",
    "moment": "^2.20.1",
    "prop-types": "^15.7.2",
    "react-apollo": "^2.0.4",
    "react-native-datepicker": "^1.7.2",
    "react-native-deck-swiper": "^1.6.7",
    "react-native-keyboard-aware-scroll-view": "^0.9.1",
    "react-native-material-dropdown": "^0.11.1",
    "react-native-modal": "^11.3.1",
    "react-native-modal-datetime-picker": "^4.13.0",
    "react-native-modal-dropdown": "^0.6.2",
    "react-native-paper": "^2.16.0",
    "react-native-responsive-screen": "^1.4.0",
    "react-native-segmented-control-tab": "^3.4.1",
    "react-native-slideable-calendar-strip": "^0.4.0",
    "react-native-snap-carousel": "^3.8.0",
    "react-native-sound": "^0.11.0",
    "react-native-svg": "9.13.3",
    "react-native-swipe-gestures": "^1.0.3",
    "react-native-swipeable": "^0.6.0",
    "react-native-swipeout": "^2.3.3",
    "react-native-touchable-swipe": "^1.0.0",
    "react-navigation": "^4.2.2",
    "react-redux": "^7.2.0",
    "redux": "^4.0.5",
    "redux-persist": "^4.10.2",
    "redux-thunk": "^2.3.0",
    "uuid": "^3.2.1"
  },

任何帮助都非常感谢,谢谢。

1个回答

如果有人遇到此问题,这是 github 上 @Ashish-Nanda 的解决方案:

您链接的问题有来自软件包维护者的回复,其中包含错误原因。 您的一个或多个依赖项可能正在从 React Native 核心导入 NetInfo。查看您的 package.json,其中一个是 aws-appsync-react,您需要将其升级到 2.x.x 以上的任何版本。从您的 package.json 中删除 aws-appsync-react 和 aws-appsync,然后安装最新版本(确保其高于 2.x.x)。然后执行以下操作:

npm install --save @react-native-community/ [email protected]

您需要安装此特定版本,因为较新的版本会随着 API 的更改而导致问题。

jibidijib
2020-03-17