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

React Native 0.74升级后iOS构建报错:react-native-config脚本执行失败

升级React Native到0.74后iOS构建失败:react-native-config代码生成脚本错误

问题详情

将React Native从0.70.7升级至0.74后,iOS构建出现如下错误:

** BUILD FAILED **

The following build commands failed:
        PhaseScriptExecution [CP-User]\ Config\ codegen /Users/hakanuysal/Library/Developer/Xcode/DerivedData/myProject-dzmuzwuniukjeedngibspubvfwbd/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/react-native-config.build/Script-46EB2E00042F70.sh (in target 'react-native-config' from project 'Pods')
(1 failure)

error Command failed with exit code 1.

项目关键配置:

  • react-native版本:0.74.0
  • react-native-config版本:1.5.0
  • Podfile启用了use_modular_headers!

原因分析

react-native-config 1.5.0版本未适配React Native 0.74升级后的Codegen工具链。RN 0.74对原生模块的代码生成流程做了调整,旧版本的react-native-config构建脚本无法兼容新流程,导致执行[CP-User] Config codegen脚本时失败。

解决方案

方案1:升级react-native-config到兼容版本

react-native-config从1.5.1版本开始适配了RN 0.73+的Codegen流程,直接升级即可解决问题:

  1. 执行升级命令:
yarn upgrade react-native-config@latest
# 或使用npm
npm install react-native-config@latest
  1. 清理iOS构建依赖并重新安装:
cd ios && rm -rf Pods Podfile.lock && pod install && cd ..
  1. 清理Xcode缓存:
    • 打开Xcode,前往File > Project Settings
    • 点击Derived Data旁的箭头,删除当前项目的DerivedData文件夹
  2. 重新执行iOS构建:yarn ios

方案2:手动禁用react-native-config的Codegen脚本(若升级后仍有问题)

如果升级后仍存在脚本执行问题,可在Podfile的post_install阶段手动移除该脚本:
在Podfile的post_install块中添加以下代码:

installer.pods_project.targets.each do |target|
  if target.name == 'react-native-config'
    target.build_configurations.each do |config|
      config.script_phases.each do |phase|
        if phase.name.include?('Config codegen')
          phase.remove_from_project
        end
      end
    end
  end
end

添加后重新执行pod install,再尝试构建。

方案3:彻底清理项目缓存

执行项目自带的清理脚本,或手动清理所有缓存:

yarn clean
# 或手动执行:
rm -rf node_modules && yarn install
watchman watch-del-all
yarn start --reset-cache

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 16:04:53