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

升级Xcode 14.3后无法编译React Native 0.65.3项目求助

Xcode 14.3编译React Native 0.65.3项目失败的解决方案

问题背景

升级Xcode至14.3后,基于React Native 0.65.3的公司项目无法编译,但RN 0.69版本的个人项目可正常运行。已尝试清理缓存、删除npm模块及Pods,问题未解决。

系统环境信息

System:
OS: macOS 13.0.1
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 150.35 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 18.15.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 9.5.0 - /usr/local/bin/npm
Watchman: 2023.02.06.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.12.0 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
Android SDK: Not Found
IDEs:
Android Studio: 2021.3 AI-213.7172.25.2113.9123335
Xcode: 14.3/14E222b - /usr/bin/xcodebuild
Languages:
Java: 11.0.11 - /usr/bin/javac
npmPackages:
@react-native-community/cli: 6.0.0 => 6.0.0
react: 17.0.2 => 17.0.2
react-native: 0.65.3 => 0.65.3
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

问题复现步骤

  • 将Xcode升级至14.3
  • 重新编译RN 0.65版本项目

核心异常

Xcode错误查找路径ReactCommon/turbomodule/core/TurboModuleUtils.h,但该文件实际路径为ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.h。官方因版本停止支持驳回问题,需找到无需降级Xcode的修复方案。


可行修复方案

方案1:修改Podfile配置并添加路径映射

在项目ios/Podfile中添加头文件路径配置,确保Xcode能找到正确的文件:

target 'YourProjectName' do
  # 保留原有配置,新增以下内容
  pod 'ReactCommon/turbomodule/core', :path => '../node_modules/react-native/ReactCommon'

  post_install do |installer|
    installer.pods_project.targets.each do |target|
      if target.name == 'ReactCommon-turbomodule_core'
        target.build_configurations.each do |config|
          # 添加正确的头文件搜索路径
          config.build_settings['HEADER_SEARCH_PATHS'] = "$(inherited) ${PODS_ROOT}/../node_modules/react-native/ReactCommon/react/nativemodule/core"
        end
      end
    end
  end
end

方案2:创建软链接映射错误路径

手动在RN依赖目录创建软链接,让错误路径指向正确文件:

cd node_modules/react-native/ReactCommon/
mkdir -p turbomodule/core
ln -s ../../react/nativemodule/core/ReactCommon/TurboModuleUtils.h turbomodule/core/TurboModuleUtils.h

为避免pod install后软链接丢失,可将命令添加到package.json的postinstall脚本:

{
  "scripts": {
    "postinstall": "cd node_modules/react-native/ReactCommon && mkdir -p turbomodule/core && ln -sf ../../react/nativemodule/core/ReactCommon/TurboModuleUtils.h turbomodule/core/TurboModuleUtils.h || true"
  }
}

方案3:直接修改Xcode项目头文件搜索路径

打开Xcode项目,找到主Target的Build Settings -> Header Search Paths,添加以下路径并设置为Recursive:

$(SRCROOT)/../node_modules/react-native/ReactCommon/react/nativemodule/core

最后执行清理与重建

完成上述任一方案后,执行以下命令清理缓存并重新构建:

rm -rf node_modules && yarn install
cd ios && pod deintegrate && pod install
cd .. && npx react-native clean

之后重新用Xcode编译项目即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 13:19:59