React Native集成Auth0报错:TypeError: null is not an object求助
React Native Auth0模块报错:
null is not an object (evaluating 'this.Auth0Module.hasValidCredentialManagerInstance') 错误信息
WARN Possible Unhandled Promise Rejection (id: 0): TypeError: null is not an object (evaluating 'this.Auth0Module.hasValidCredentialManagerInstance')
异常情况
更新:在Android Studio中运行模拟器完全正常,但从VSCode启动模拟器时必现该错误。
背景说明
环境变量正常生效,Auth0后台已配置好对应的应用回调URI。我知道这个错误是Auth0Module对象为空导致找不到属性,但不知道从哪下手解决,求可行的排查方向。
相关代码
App.js
import {AUTH0_DOMAIN, CLIENT_ID} from '@env'; import { StatusBar } from 'expo-status-bar'; import React from 'react'; import { Button, StyleSheet, Text, View } from 'react-native'; import {useAuth0, Auth0Provider} from 'react-native-auth0'; export default function App() { return ( <Auth0Provider domain={`${AUTH0_DOMAIN}`} clientId={`${CLIENT_ID}`}> <View style={styles.container}> <Text style={styles.title}>Open up App.js to start working on your app!</Text> <StatusBar style="auto" /> <LoginButton /> </View> </Auth0Provider> ); }; const LoginButton = () => { const {authorize} = useAuth0(); const onPress = async () => { try { await authorize(); } catch(error) { console.log('this is an error: ',error); } } return <Button onPress={onPress} title="Log In"></Button> } console.log(AUTH0_DOMAIN); const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#4f5', alignItems: 'center', justifyContent: 'center', borderStyle: 'solid', borderColor: 'black', borderWidth: 5, }, title : { fontSize: 30, } });
app.json
{ "expo": { "name": "myPackage", "slug": "myPackage", "version": "1.0.0", "orientation": "portrait", "icon": "./assets/icon.png", "userInterfaceStyle": "light", "splash": { "image": "./assets/splash.png", "resizeMode": "contain", "backgroundColor": "#ffffff" }, "assetBundlePatterns": [ "**/*" ], "ios": { "supportsTablet": true }, "android": { "adaptiveIcon": { "foregroundImage": "./assets/adaptive-icon.png", "backgroundColor": "#ffffff" }, "package": "com.myPackage" }, "web": { "favicon": "./assets/favicon.png" }, "plugins": [ [ "react-native-auth0", { "domain": "myDomain" } ] ] } }
错误截图

排查建议
- 统一VSCode和Android Studio的adb环境:
在VSCode终端执行which adb,对比Android Studio终端的输出,确保两者使用的是同一个adb版本。如果路径不同,把Android Studio的adb路径添加到系统环境变量中,重启VSCode后再试。 - 清理并重新构建Native模块:
执行expo prebuild --clean清除旧的构建缓存,之后重新运行项目,确保react-native-auth0的Native代码被正确编译集成。 - 修正Auth0插件配置:
app.json中react-native-auth0插件的domain字段建议改用环境变量,替换为"domain": "${AUTH0_DOMAIN}",保证和Auth0Provider中传入的domain一致,避免初始化不匹配。 - 检查Android权限配置:
确认android/app/src/main/AndroidManifest.xml中包含以下权限,react-native-auth0依赖这些权限完成凭证管理:<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" />
内容的提问来源于stack exchange,提问作者Lauro235
相关产品推荐
相关产品推荐

