RN 0.73.1 iOS编译报错:'react/debug/react_native_assert.h'文件缺失
问题描述
运行React Native 0.73.1版本的iOS项目时,遭遇编译错误:'react/debug/react_native_assert.h' file not found,报错关联React-utils/RunLoopObserver模块。

Podfile配置
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! pod 'react-native-video', :path => '../node_modules/react-native-video/react-native-video.podspec' pod 'RNPermissions', :path => '../node_modules/react-native-permissions' pod 'ffmpeg-kit-react-native', :subspecs => ['min-gpl-lts'], :podspec => '../node_modules/ffmpeg-kit-react-native/ffmpeg-kit-react-native.podspec' permissions_path = '../node_modules/react-native-permissions/ios' pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications" pod 'Permission-Camera', :path => "#{permissions_path}/Camera" pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone" pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary" flipper_config = FlipperConfiguration.disabled linkage = ENV['USE_FRAMEWORKS'] abstract_target 'CommonPods' do config = use_native_modules! use_frameworks! :linkage => :static $RNFirebaseAsStaticFramework = true pod 'RNCPushNotificationIOS', :path => '../node_modules/@react-native-community/push-notification-ios' use_react_native!( :path => config[:reactNativePath], :app_path => "#{Pod::Config.instance.installation_root}/.." ) 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| config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO' config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO' if ["React-cxxreact", "React-NativeModulesApple", "RNGestureHandler", "RNScreens", "React-utils", "React-debug", "React-runtimescheduler"].any? { |t| t == target.name } append_header_search_path(target, "${PODS_ROOT}/../../node_modules/react-native/ReactCommon") end end end end def append_header_search_path(target, path) target.build_configurations.each do |config| config.build_settings["HEADER_SEARCH_PATHS"] ||= "$(inherited) " config.build_settings["HEADER_SEARCH_PATHS"] << path end end pod 'Firebase' pod 'FirebaseCore' pod 'FirebaseCoreInternal' pod 'FirebaseCoreExtension' pod 'FirebaseInstallations' pod 'FirebaseABTesting' pod 'FirebaseFirestoreInternal' pod 'GoogleUtilities' pod 'GoogleDataTransport' pod 'nanopb' target 'Dev' do end target 'QA' do end end
环境信息
- 系统: macOS 14.1,Apple M1 Pro(10核),内存16GB
- Shell: zsh 5.9
- 二进制工具:
- Node: 20.5.1
- Yarn: 1.22.18
- npm: 9.8.0
- Watchman: 2023.08.14.00
- 包管理器: CocoaPods 1.14.3
- SDK:
- iOS SDK: 17.0(含DriverKit 23.0、macOS 14.0等)
- Android SDK: API 28-33,NDK 22.1.7171670
- IDE:
- Android Studio 2022.3
- Xcode 15.0
- React Native配置:
- iOS: Hermes启用,新架构未启用
- Android: Hermes启用,新架构未启用
解决方案
1. 完善Header Search Paths配置
react_native_assert.h位于react-native/ReactCommon/react/debug目录下,现有Podfile的路径配置不够完整。修改post_install里的路径添加逻辑,改为递归搜索:
if ["React-cxxreact", "React-NativeModulesApple", "RNGestureHandler", "RNScreens", "React-utils", "React-debug", "React-runtimescheduler"].any? { |t| t == target.name } append_header_search_path(target, "${PODS_ROOT}/../../node_modules/react-native/ReactCommon/**") end
**会递归遍历子目录,确保所有层级的头文件都能被找到。
2. 彻底清理并重建依赖
执行以下命令清理缓存和冗余文件,重新安装依赖:
# 删除前端依赖和锁文件 rm -rf node_modules package-lock.json yarn.lock npm install # 清理iOS构建文件 cd ios rm -rf Pods Podfile.lock build pod install --repo-update # 清理Metro缓存 cd .. npx react-native start --reset-cache
3. 确认React Native版本一致性
检查package.json中react-native版本是否为0.73.1,执行命令验证:
npm list react-native
若版本不符,重新安装指定版本:
npm install react-native@0.73.1 --save-exact
4. 调整React Native Pod引用配置
确保use_react_native!配置明确,显式指定路径和Hermes状态:
use_react_native!( :path => "../node_modules/react-native", :hermes_enabled => true )
5. 检查Xcode项目配置
打开iOS项目的.xcworkspace,找到React-utils target的Build Settings:
- 确认
Header Search Paths包含$(SRCROOT)/../node_modules/react-native/ReactCommon/** - 将
Always Search User Paths设置为YES
内容的提问来源于stack exchange,提问作者Chamitha Narawita
相关产品推荐
相关产品推荐

