You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo Go运行应用报错:访问不存在的Native Module求助

Expo Go运行应用时Native Module不存在错误排查与解决

问题描述

每次执行npx expo start --tunnel并扫描二维码后,iOS打包完成但终端弹出以下错误,导致应用无法启动:

Error: Invariant Violation: Your Javascript code tried to access a native module that doesn't exist

错误详情:

If you're trying to use a module that is not supported in Expo Go, you need to create a development build of your app. See https://docs.expo.dev/development/introduction/ for more info.
ERROR Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter.
A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading 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
}

已尝试方案

  • 删除node_modules后重新执行npm install
  • 参考Stack Overflow相关问题
  • 参考GitHub上React Native的相关Issue

解决方案

1. 核心原因定位

Expo Go是预构建客户端,仅支持Expo官方维护的模块。你的项目中@react-native-firebase/app、@react-native-firebase/auth、react-native-google-signin均为第三方原生模块,无法在Expo Go中直接运行。同时存在导航版本冲突、冗余依赖问题,进一步触发了初始化错误。

2. 具体修复步骤

步骤1:清理冗余依赖

移除项目中无用的后端/无效依赖:

npm uninstall ios pod express mongoose react-navigation react-navigation-stack

步骤2:选择适配方案

方案A:改用Expo官方支持的Firebase模块(无需开发构建)

安装Expo维护的Firebase包:

npx expo install expo-firebase-app expo-firebase-auth

修改App.js中的导入语句:

// 替换原有的@react-native-firebase/auth导入
import auth from 'expo-firebase-auth'

按照Expo官方流程配置Firebase项目后,即可在Expo Go中正常运行。

方案B:保留原生模块,创建开发构建

若坚持使用@react-native-firebase等原生模块,需创建自定义开发客户端:

  1. 安装开发客户端依赖:
npx expo install expo-dev-client
  1. 在app.json中添加插件配置:
{
  "expo": {
    "plugins": ["expo-dev-client"]
  }
}
  1. 构建iOS开发客户端:
eas build --platform ios --profile development
  1. 将构建好的客户端安装到测试设备,扫码运行项目。

步骤3:统一导航版本

确认仅使用@react-navigation v6版本,当前App.js中的NavigationContainer和createStackNavigator已符合v6规范,清理旧版依赖后即可避免冲突。

内容的提问来源于stack exchange,提问作者Pickle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 03:15:50