引入AWS Amplify库导致Expo React Native应用出现TypeError
AWS Amplify引入触发TypeError错误
我有一个用AWS Amplify实现身份认证的Expo React Native项目,只要引入任意Amplify相关库(比如引入CognitoAccessToken、Auth等模块,或是仅引入Authenticator组件),就会触发多个TypeError错误,包括**"Super expression must either be null or a function"和"Cannot read property 'unstable_settings' of undefined"**。
错误栈信息
ERROR TypeError: Super expression must either be null or a function, js engine: hermes at RootRouteNodeProvider (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:143613:23) at ContextNavigator (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:148703:24) at RNCSafeAreaProvider at SafeAreaProvider (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:136559:24) at RNGestureHandlerRootView at GestureHandlerRootView at GestureHandler at ExpoRoot (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:148688:24) at App at withDevTools(App) (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:128372:27) at RCTView at View (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:61481:43) at RCTView at View (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:61481:43) at AppContainer (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:61342:36) at main(RootComponent) (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:107126:28) ERROR TypeError: Super expression must either be null or a function, js engine: hermes at RootRouteNodeProvider (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:143613:23) at ContextNavigator (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:148703:24) at RNCSafeAreaProvider at SafeAreaProvider (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:136559:24) at RNGestureHandlerRootView at GestureHandlerRootView at GestureHandler at ExpoRoot (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:148688:24) at App at withDevTools(App) (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:128372:27) at RCTView at View (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:61481:43) at RCTView at View (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:61481:43) at AppContainer (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:61342:36) at main(RootComponent) (http://192.168.0.15:19000/index.tsx.bundle//&platform=android&dev=true&hot=false:107126:28) ERROR TypeError: Cannot read property 'unstable_settings' of undefined This error is located at: in RootRouteNodeProvider (created by ContextNavigator) in ContextNavigator (created by ExpoRoot) in RNCSafeAreaProvider (created by SafeAreaProvider) in SafeAreaProvider (created by ExpoRoot) in RNGestureHandlerRootView (created by GestureHandlerRootView) in GestureHandlerRootView (created by GestureHandler) in GestureHandler (created by ExpoRoot) in ExpoRoot (created by App) in App (created by withDevTools(App)) in withDevTools(App) in RCTView (created by View) in View (created by AppContainer) in RCTView (created by View) in View (created by AppContainer) in AppContainer in main(RootComponent), js engine: hermes ERROR TypeError: Cannot read property 'unstable_settings' of undefined This error is located at: in RootRouteNodeProvider (created by ContextNavigator) in ContextNavigator (created by ExpoRoot) in RNCSafeAreaProvider (created by SafeAreaProvider) in SafeAreaProvider (created by ExpoRoot) in RNGestureHandlerRootView (created by GestureHandlerRootView) in GestureHandlerRootView (created by GestureHandler) in GestureHandler (created by ExpoRoot) in ExpoRoot (created by App) in App (created by withDevTools(App)) in withDevTools(App) in RCTView (created by View) in View (created by AppContainer) in RCTView (created by View) in View (created by AppContainer) in AppContainer in main(RootComponent), js engine: hermes
触发错误的引入代码示例
多模块引入
import { CognitoAccessToken } from "amazon-cognito-identity-js"; import { HubCapsule } from "@aws-amplify/core/lib/Hub"; import { CognitoUserSession } from "amazon-cognito-identity-js"; import { Auth, Hub, Logger } from "aws-amplify"; import { useEffect } from "react";
仅引入Authenticator组件
import { Authenticator } from '@aws-amplify/ui-react-native';
项目依赖版本
{ "dependencies": { "@aws-amplify/ui-react-native": "1.2.18", "@expo/metro-config": "0.7.1", "@expo/vector-icons": "13.0.0", "@octokit/core": "4.2.0", "@pchmn/expo-material3-theme": "1.0.0", "@react-native-async-storage/async-storage": "1.17.11", "@react-native-community/netinfo": "9.3.7", "@tanstack/react-query": "4.29.3", "amazon-cognito-identity-js": "6.2.0", "aws-amplify": "5.1.2", "metro-cache": "0.76.5", "expo": "48.0.17", "expo-asset": "8.9.1", "expo-constants": "14.2.1", "expo-linking": "4.0.1", "expo-modules-autolinking": "1.1.2", "expo-router": "1.5.3", "expo-secure-store": "12.1.1", "expo-splash-screen": "0.18.1", "expo-status-bar": "1.4.4", "immer": "9.0.21", "react": "^18.2.0", "react-dom": "^18.2.0", "react-native": "0.71.8", "react-native-gesture-handler": "2.9.0", "react-native-paper": "5.5.2", "react-native-reanimated": "2.14.4", "react-native-safe-area-context": "4.5.0", "react-native-screens": "3.20.0", "react-native-svg": "13.4.0", "react-native-url-polyfill": "1.3.0", "react-native-vector-icons": "9.2.0", "react-native-web": "0.18.12", "zustand": "4.3.7" }, "devDependencies": { "@babel/core": "^7.21.4", "@babel/plugin-proposal-object-rest-spread": "7.0.0", "@babel/preset-env": "7.21.4", "@babel/preset-react": "7.0.0", "@babel/runtime": "7.21.0", "@expo/metro-runtime": "2.0.4", "@tsconfig/react-native": "2.0.3", "@types/react": "^18.0.28", "babel-core": "7.0.0-bridge.0", "babel-loader": "8.0.0-beta.6", "babel-plugin-transform-inline-environment-variables": "0.4.4", "dotenv-cli": "^7.1.0", "metro": "0.76.5", "metro-config": "0.76.5", "react-native-svg-transformer": "1.0.0", "rome": "12.1.0", "typescript": "4.9.5", "webpack": "4.23.1", "webpack-cli": "3.1.2" }, "private": true }
内容的提问来源于stack exchange,提问作者Nikola-Milovic
相关产品推荐
相关产品推荐

