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

执行npx react-native run-ios时Hermes引擎报错求助

解决React Native run-ios时AppRegistry未注册报错

报错信息

ERROR  TypeError: undefined is not a function, js engine: hermes
ERROR  Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Bridgeless Mode: false. Registered callable JavaScript modules (n = 9): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, 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

已尝试无效操作

  • 重新安装Pod:rm -rf Pods/ && rm -rf Podfile.lock && pod install
  • 更新Pod
  • 清理npm缓存
  • 卸载重装node_modules
  • 改用Yarn安装依赖

可行排查方案

1. 验证入口文件配置

  • 检查ios/<项目名称>/AppDelegate.mm(或.m)中的入口路径是否正确,确保指向项目根目录的index.js/index.tsx:
    - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
    {
      #ifdef DEBUG
        return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
      #else
        return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
      #endif
    }
    
  • 确认根目录入口文件中正确注册App:
    import { AppRegistry } from 'react-native';
    import App from './App';
    import { name as appName } from './app.json';
    
    AppRegistry.registerComponent(appName, () => App);
    

2. 排查Hermes引擎兼容性

  • 临时禁用Hermes,修改ios/Podfile:
    use_react_native!(
      :path => config[:reactNativePath],
      # 注释此行以禁用Hermes
      # :hermes_enabled => true
    )
    
    执行pod install后重新运行项目,若恢复正常则说明Hermes存在配置或语法兼容问题,可尝试更新Hermes版本或排查代码中不兼容语法。

3. 清理iOS构建缓存

  • 打开Xcode执行Product > Clean Build Folder(快捷键Cmd+Shift+K)
  • 删除DerivedData目录:rm -rf ~/Library/Developer/Xcode/DerivedData
  • 重新执行npx react-native run-ios

4. 定位早期初始化错误

  • 打开远程调试(Cmd+D唤起开发者菜单,选择Debug JS Remotely),查看Chrome控制台的完整报错日志,定位AppRegistry注册前的模块导入、语法错误等问题。
  • 临时替换App.js为最简组件,排查是否为业务代码导致的初始化失败:
    import React from 'react';
    import { View, Text } from 'react-native';
    
    const App = () => {
      return (
        <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
          <Text>Test</Text>
        </View>
      );
    };
    
    export default App;
    

5. 确认版本兼容性

  • 检查package.json中react与react-native版本是否匹配,无冲突可尝试升级到稳定版本:
    npm install react-native@latest react@latest
    
    重新安装依赖及Pod后运行项目。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 09:00:17