每次在 expo go 上运行我的应用程序时,我都会收到以下错误:错误:不变违规:您的 Javascript 代码尝试访问不存在的本机模块。
在我运行 npx expo start --tunnel 并扫描二维码后会发生这种情况。 IOS 捆绑完成,但我从未看到该应用程序,因为终端中出现上述错误。
我的错误还有几行:
如果您尝试使用 Expo Go 不支持的模块,您需要创建应用程序的开发版本。请参阅 https://docs.expo.dev/development/introduction/ 了解更多信息。 错误不变违规:无法调用 JavaScript 模块方法 AppRegistry.runApplication()。模块尚未注册为可调用。注册的可调用 JavaScript 模块 (n = 11):Systrace、JSTimers、HeapCapture、SamplingProfiler、RCTLog、RCTDeviceEventEmitter、RCTNativeAppEventEmitter、GlobalPerformanceLogger、JSDevSupportModule、HMRClient、RCTEventEmitter。 导致该错误的常见原因是应用程序入口文件路径不正确。当 JS 包损坏或加载 React Native 时出现早期初始化错误时,也可能会发生这种情况。
错误不变违规:无法调用 JavaScript 模块方法 AppRegistry.runApplication()。模块尚未注册为可调用。注册的可调用 JavaScript 模块 (n = 11):Systrace、JSTimers、HeapCapture、SamplingProfiler、RCTLog、RCTDeviceEventEmitter、RCTNativeAppEventEmitter、GlobalPerformanceLogger、JSDevSupportModule、HMRClient、RCTEventEmitter。 导致该错误的常见原因是应用程序入口文件路径不正确。当 JS 包损坏或加载 React Native 时出现早期初始化错误时,也可能会发生这种情况。
这是我的 App.js 代码,我在其中显示我的应用程序:
import React from 'react';
import { Provider } from 'react-native-paper'
import { NavigationContainer } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'
import { theme } from './src/core/theme'
import auth from '@react-native-firebase/auth'
import StartScreen from './src/screens/StartScreen'
import LoginScreen from './src/screens/LoginScreen'
import RegisterScreen from './src/screens/RegisterScreen'
import ResetPasswordScreen from './src/screens/ResetPasswordScreen'
import Dashboard from './src/screens/Dashboard'
import ProfileScreen from './src/screens/Profile'
const Stack = createStackNavigator()
export default function App() {
return (
<Provider theme={theme}>
<NavigationContainer>
<Stack.Navigator
initialRouteName="StartScreen"
screenOptions={{
headerShown: true,
}}
>
<Stack.Screen name="StartScreen" component={StartScreen} />
<Stack.Screen name="LoginScreen" component={LoginScreen} />
<Stack.Screen name="RegisterScreen" component={RegisterScreen} />
<Stack.Screen name="Dashboard" component={Dashboard} />
<Stack.Screen name="ResetPasswordScreen" component={ResetPasswordScreen}/>
<Stack.Screen name="ProfileScreen" component={ProfileScreen}/>
</Stack.Navigator>
</NavigationContainer>
</Provider>
)
}
这是我的 package.json 代码以及所有依赖项:
{
"name": "rn-starter-update",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"@draftbit/ui": "^46.5.1",
"@react-native-community/masked-view": "^0.1.11",
"@react-native-firebase/app": "^16.5.0",
"@react-native-firebase/auth": "^16.5.0",
"@react-navigation/stack": "^6.3.7",
"expo": "~47.0.3",
"expo-constants": "^14.0.2",
"expo-status-bar": "~1.4.2",
"express": "^4.18.2",
"firebase": "8.2.3",
"ios": "^0.0.1",
"mongoose": "^6.7.2",
"pod": "^0.9.0",
"react": "18.1.0",
"react-native": "^0.70.5",
"react-native-gesture-handler": "~2.8.0",
"react-native-google-signin": "^2.1.1",
"react-native-paper": "^4.12.5",
"react-native-reanimated": "~2.12.0",
"react-native-safe-area-context": "4.4.1",
"react-native-screens": "~3.18.0",
"react-native-status-bar-height": "^2.6.0",
"react-navigation": "^4.4.4",
"react-navigation-stack": "^2.10.4"
},
"devDependencies": {
"@babel/core": "^7.12.9"
},
"private": true
}
我尝试过的解决方案:
3.https://github.com/facebook/react-native/issues/26687
谢谢您的帮助!
安装@react-native-firebase/app后我遇到了同样的问题。
@react-native-firebase/app 包是原生模块,不能在 Expo Go(expo start)中使用。
要在 expo 中使用本机模块,您必须使用带有 expo-dev-client 包的开发版本。
有关开发版本以及如何设置的更多信息,请访问:https://docs.expo.dev/development/introduction/
我必须将 package.json 中的 "main": "App.js" 更新为 "main": "node_modules/expo/AppEntry.js" 并运行 "npm i",然后运行 "npx expo start" 以在 ExpoGo 应用程序中显示。如果仍有问题,请运行“npx expo start --tunnel”