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

React-Native从0.69升级到0.72.3后遇两类错误求助

React Native 0.72.3升级后:Reanimated未初始化+AppRegistry注册失败解决指南

一、优先解决Reanimated原生未初始化问题

该问题大概率会连锁导致AppRegistry注册失败,需先处理:

1. 锁定适配RN0.72的Reanimated版本

Reanimated 3.x系列适配RN0.71+,执行以下命令安装对应版本:

npm install react-native-reanimated@^3.3.0 --save
# 或使用yarn
yarn add react-native-reanimated@^3.3.0

2. iOS端强制清理并重建依赖

  • 进入iOS目录,完全清理旧Pod依赖:
    cd ios
    pod deintegrate
    rm -rf Podfile.lock
    rm -rf ~/Library/Caches/CocoaPods
    rm -rf ../node_modules/.cache
    
  • 重新安装Pod:
    pod install
    
  • 检查Xcode配置:
    1. 打开项目Target → Build Phases,添加Run Script Phase,内容为:
      "${SRCROOT}/../node_modules/react-native-reanimated/scripts/ios-configure-glog.sh"
      
    2. 确认Podfile中启用静态框架与Hermes:
      use_frameworks! :linkage => :static
      use_react_native!(:path => config["reactNativePath"], :hermes_enabled => true)
      

3. Android端配置校验与缓存清理

  • 检查android/app/build.gradle:
    dependencies {
      // 确保存在Reanimated依赖
      implementation project(':react-native-reanimated')
    }
    // 确认Hermes开启
    project.ext.react = [
      enableHermes: true
    ]
    
  • 检查android/settings.gradle:
    include ':react-native-reanimated'
    project(':react-native-reanimated').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-reanimated/android')
    
  • 清理并重新编译:
    cd android
    ./gradlew clean
    ./gradlew assembleDebug
    

4. Babel配置校验

确保babel.config.js中Reanimated插件放在最后:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    // 其他插件放前面
    'react-native-reanimated/plugin' // 必须是最后一个插件
  ],
};

二、解决AppRegistry未注册问题

若处理完Reanimated问题后仍报错,执行以下操作:

1. 重启Metro服务(必须从项目根目录启动)

# 关闭所有Metro进程,然后执行
npx react-native start --reset-cache

2. 校验App注册逻辑

  • 检查app.json中的name字段是否为deepmart
  • 确认入口文件(index.js/App.js)末尾存在注册代码:
    import { AppRegistry } from 'react-native';
    import App from './App';
    import { name as appName } from './app.json';
    
    AppRegistry.registerComponent(appName, () => App);
    

3. 强制生成JS Bundle(iOS)

npx react-native bundle --platform ios --dev false --entry-file index.js --bundle-output ios/main.jsbundle --assets-dest ios

执行完成后重新运行iOS项目


进阶排查

  • 新建空白RN0.72.3项目,安装Reanimated并运行,确认基础环境无问题
  • 查看Metro控制台的完整日志,排除其他模块加载错误(Reanimated的错误可能掩盖前置异常)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 22:47:38