React Native项目Xcode构建时AppRegistry注册失败报错求助
问题描述
通过Xcode将React Native项目构建到iPhone(及iOS模拟器)时出现以下报错:
Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 10): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient. 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., js engine: hermes
已尝试的操作:
- 用gesture handler包裹App.js元素
- 删除并重新在设备上安装应用
- 执行
npm i - 执行
cd ios && pod install - 重启电脑
- 重新打开Xcode
该问题仅出现在单个React Native项目中,此前运行正常,断开iPhone后重新构建时触发,且iOS模拟器运行也会抛出相同报错。
修复建议
1. 检查入口文件配置
- 确认
index.js(或index.ios.js)中是否正确注册App:import { AppRegistry } from 'react-native'; import App from './App'; import { name as appName } from './app.json'; AppRegistry.registerComponent(appName, () => App); - 检查Xcode中
Build Phases->Bundle React Native code and images脚本里的入口文件路径是否正确,默认指向index.js,自定义路径需确保无误。
2. 清理缓存与重建JS bundle
- 清理React Native缓存:
npx react-native start --reset-cache - 手动删除iOS项目的Derived Data:打开Xcode,点击
Xcode->Settings->Locations,找到Derived Data路径,删除对应项目的文件夹。 - 清理npm缓存并重新安装依赖:
npm cache clean --force rm -rf node_modules npm install cd ios && pod deintegrate && pod install
3. 检查Hermes相关配置
- 确认项目中Hermes是否正确启用:检查
ios/Podfile中是否有use_react_native!(..., :hermes_enabled => true),且已执行pod install。 - 暂时禁用Hermes测试:在
ios/Podfile中将hermes_enabled设为false,重新执行pod install后构建项目,排查是否为Hermes相关问题。
4. 排查初始化阶段错误
- 逐步注释App.js或入口文件中的非核心初始化代码(如第三方SDK配置、自定义hooks),定位是否有未捕获的异常导致模块注册失败。
- 开启React Native调试模式,查看控制台是否有更多详细报错信息。
5. 检查项目文件完整性
- 确认
app.json中的name字段与AppRegistry.registerComponent中使用的appName完全一致。 - 检查
index.js、App.js等核心文件是否被误删或篡改。
内容的提问来源于stack exchange,提问作者Siyac8
相关产品推荐
相关产品推荐

