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

安装react-native-reanimated后React Native应用iOS端构建失败求助

解决方案

这个错误是react-native-reanimated版本和你当前使用的React Native版本不兼容,或是依赖配置不完整导致的,按以下步骤操作即可解决:

  • 第一步:匹配版本
    先确认你项目的React Native版本,安装对应兼容的reanimated版本:
    • React Native 0.66~0.67:使用reanimated 2.3.x~2.7.x
    • React Native 0.68~0.70:使用reanimated 2.8.x~2.17.x
    • React Native 0.71及以上:使用reanimated 3.x版本
      卸载原有版本重装的命令:
    # 卸载旧版本
    npm uninstall react-native-reanimated
    # 安装对应匹配版本,举例安装3.6.1版本
    npm install react-native-reanimated@3.6.1
    
  • 第二步:配置Babel插件
    打开项目根目录的babel.config.js,在plugins数组的最后添加reanimated的插件,示例配置:
    module.exports = {
      presets: ['module:metro-react-native-babel-preset'],
      plugins: [
        // 其他插件保持不变
        'react-native-reanimated/plugin', // 必须放在所有插件的最后一位
      ],
    };
    
  • 第三步:全量清理缓存重新构建
    按顺序执行以下命令:
    # 清理项目依赖缓存
    rm -rf node_modules package-lock.json yarn.lock
    # 重新安装依赖
    npm install
    # 清理iOS构建缓存
    cd ios
    rm -rf Pods Podfile.lock build ~/Library/Developer/Xcode/DerivedData/*
    pod install
    cd ..
    # 启动RN服务时清空缓存
    npx react-native start --reset-cache
    # 新开终端执行iOS构建
    npx react-native run-ios
    
  • 额外说明:如果你开启了React Native的Fabric新架构,需要确认当前reanimated版本适配对应RN的新架构,若适配存在问题可暂时在ios/Podfile中设置:fabric_enabled => false,关闭新架构后重新执行pod install再构建。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.01 03:27:03