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

React Native项目报错:ReactCodegen Command PhaseScriptExecution执行失败

React Native iOS构建错误:ReactCodegen PhaseScriptExecution失败修复方案

问题现象

ReactCodegen : Command PhaseScriptExecution failed with a nonzero exit code

以下针对你的Podfile和package.json给出针对性修改建议:


Podfile 修改方案

优化后完整配置

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, min_ios_version_supported
prepare_react_native_project!

# 统一管理框架链接逻辑,避免重复声明
linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
else
  # 默认使用静态框架,适配React Native 0.75+及Firebase生态
  use_frameworks! :linkage => :static
end

target 'AppName' do
  config = use_native_modules!

  # React Native核心依赖配置
  use_react_native!(
    :path => config[:reactNativePath],
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'AppNameTests' do
    inherit! :complete
    # Pods for testing
  end

  post_install do |installer|
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false,
    )

    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        # 适配Xcode 14+的Swift版本要求
        config.build_settings['SWIFT_VERSION'] = '5.3'
        # 保持部署目标与项目全局配置一致
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = min_ios_version_supported
        # 仅测试Target关闭代码签名
        if target.name.include?('Tests')
          config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
        end
      end
    end
  end
end

修改要点

  • 移除target内重复的use_frameworks!声明,统一通过全局逻辑管理框架链接方式,避免冲突
  • 删除手动添加的Firebase系列pods,use_native_modules!会自动处理@react-native-firebase依赖的集成,避免版本不匹配
  • 移除DT_TOOLCHAIN_DIR替换代码,React Native 0.75.2已内置修复该Xcode兼容性问题
  • 调整Swift版本为5.3,适配多数第三方依赖和Xcode新版本要求
  • 仅在测试Target关闭代码签名,主Target保留默认签名配置,避免真机运行/打包异常

package.json 修改方案

优化后核心依赖配置

{
  "name": "AppName",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@gorhom/bottom-sheet": "^5.0.5",
    "@invertase/react-native-apple-authentication": "^2.4.0",
    "@react-native-async-storage/async-storage": "^1.24.0",
    "@react-native-community/datetimepicker": "^8.2.0",
    "@react-native-community/slider": "^4.5.2",
    "@react-native-firebase/analytics": "^21.6.1",
    "@react-native-firebase/app": "^21.6.1",
    "@react-native-firebase/auth": "^21.6.1",
    "@react-native-firebase/firestore": "^21.6.1",
    "@react-native-google-signin/google-signin": "^13.1.0",
    "@react-navigation/native": "^6.1.18",
    "@react-navigation/native-stack": "^6.11.0",
    "cloudinary-react-native": "^1.0.1",
    "events": "^3.3.0",
    "firebase": "^10.12.0", // 与@react-native-firebase版本严格对齐
    "react": "18.3.1",
    "react-native": "0.75.2",
    "react-native-blob-util": "^0.19.11",
    "react-native-file-viewer": "^2.2.1",
    "react-native-fs": "^2.20.0",
    "react-native-gesture-handler": "^2.20.2",
    "react-native-image-zoom-viewer": "^3.0.2", // 更新适配RN 0.75
    "react-native-paper": "^5.12.5",
    "react-native-pdf": "^6.8.0", // 更新适配RN 0.75
    "react-native-permissions": "^4.1.5",
    "react-native-safe-area-context": "^4.10.9",
    "react-native-screens": "^3.34.0",
    "react-native-svg": "^15.6.0",
    "react-native-toast-message": "^2.2.1",
    "react-native-view-shot": "^4.0.2"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.75.2",
    "@react-native/eslint-config": "0.75.2",
    "@react-native/metro-config": "0.75.2",
    "@react-native/typescript-config": "0.75.2",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.3.1",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  }
}

修改要点

  • 对齐firebase与@react-native-firebase版本:RN Firebase 21.x系列对应Firebase核心库10.12.x版本,版本不匹配会触发代码生成阶段报错
  • 更新react-native-pdf和react-native-image-zoom-viewer到适配RN 0.75的版本,修复原生代码生成冲突

执行步骤

  1. 删除node_modules、ios/Pods、ios/Podfile.lock
  2. 执行npm install或yarn install
  3. 进入ios目录执行pod install --repo-update
  4. 清理Xcode缓存(Cmd+Shift+K)后重新构建

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 05:15:01