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

React Native iOS运行失败:node:internal ERR_UNHANDLED_REJECTION报错求助

React Native iOS构建失败:abseil弃用API错误及未处理Promise报错

将React Native应用升级至0.72.6版本后,执行react-native run-ios命令时构建失败,出现以下错误:

myproject/ios/Pods/Headers/Public/abseil/absl/meta/type_traits.h:301:36: builtin __has_trivial_destructor is deprecated; use __is_trivially_destructible instead [-Wdeprecated-builtins]

    : std::integral_constant<bool, __has_trivial_destructor(T) &&
                   ^

node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "Error: Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by opening Trygghetsmobilen.xcworkspace.".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

尝试切换到React Native 0.71.13版本,搭配Node 16、18版本后,仍出现相同错误,且确认项目代码中并无未处理的Promise。

开发环境信息

System:
  OS: macOS 14.0
  CPU: (10) arm64 Apple M1 Pro
  Memory: 1.71 GB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 16.17.0
    path: ~/.nvm/versions/node/v16.17.0/bin/node
  Yarn:
    version: 3.6.4
    path: ~/.nvm/versions/node/v16.17.0/bin/yarn
  npm:
    version: 8.15.0
    path: ~/.nvm/versions/node/v16.17.0/bin/npm
  Watchman:
    version: 2023.02.13.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods: Not Found
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.0
      - iOS 17.0
      - macOS 14.0
      - tvOS 17.0
      - watchOS 10.0
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.1 AI-221.6008.13.2211.9619390
  Xcode:
    version: 15.0/15A240d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.15
    path: /Users/amir/.sdkman/candidates/java/current/bin/javac
  Ruby:
    version: 2.7.5
    path: /Users/amir/.rvm/rubies/ruby-2.7.5/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.6
    wanted: 0.72.6
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

问题排查与解决方案

1. 核心原因

Xcode 15(clang 15)将__has_trivial_destructor标记为弃用,而项目依赖的abseil版本未适配该变化,导致构建时触发错误(默认Xcode会将弃用警告视为错误终止构建);未处理Promise报错是构建失败后的连锁反应,并非项目代码问题。

2. 具体修复步骤

  • 步骤1:安装并更新CocoaPods
    环境信息显示CocoaPods未安装,先执行安装:

    sudo gem install cocoapods
    

    进入iOS目录清理并重新安装依赖:

    cd ios
    pod deintegrate
    rm Podfile.lock
    pod install
    
  • 步骤2:强制更新abseil到兼容Xcode 15的版本
    在iOS目录的Podfile中添加以下配置,指定兼容版本:

    pod 'abseil', :git => 'https://github.com/abseil/abseil-cpp.git', :tag => '20230802.0'
    

    执行更新命令:

    pod update abseil
    
  • 步骤3:临时忽略弃用警告(备选方案)
    若无法更新abseil,可调整Xcode构建设置:

    1. 打开Trygghetsmobilen.xcworkspace
    2. 选中项目主Target,进入Build Settings
    3. 搜索Other C Flags,添加-Wno-deprecated-builtins
    4. 搜索Other C++ Flags,同样添加-Wno-deprecated-builtins
  • 步骤4:安装React Native CLI
    环境信息显示@react-native-community/cli未找到,执行安装:

    npm install @react-native-community/cli --save-dev
    

3. 验证修复

完成上述步骤后,重新执行react-native run-ios检查构建状态。

内容的提问来源于stack exchange,提问作者Amir-Mousavi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 21:24:51