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

React Native执行pod install遇JSON解析错误,求解决方案

React Native执行pod install时JSON解析错误的解决方法

在React Native项目目录执行pod install命令安装CocoaPods依赖时,遇到JSON解析错误,提示无法解析文件/Users/apple/.cocoapods/repos/trunk/Specs/0/b/5/PromisesObjC/2.3.1/PromisesObjC.podspec.json,859位置存在意外令牌。

环境信息

  • CocoaPods: 1.14.0
  • Ruby: ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [arm64-darwin22]
  • RubyGems: 3.3.26
  • Host: macOS 13.0 (22A380)
  • Xcode: 14.3.1 (14E300c)
  • Git: git version 2.39.2 (Apple Git-143)
  • Ruby lib dir: /Users/apple/.rbenv/versions/3.1.4/lib
  • Repositories: trunk - CDN - https://cdn.cocoapods.org/
  • Plugins:
    • cocoapods-deintegrate: 1.0.5
    • cocoapods-plugins: 1.0.0
    • cocoapods-search: 1.0.1
    • cocoapods-trunk: 1.6.0
    • cocoapods-try: 1.2.0

Podfile内容

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, min_ios_version_supported
prepare_react_native_project!

# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
#
# To fix this you can also exclude `react-native-flipper` using a `react-native.config.js`
# ```js
# module.exports = {
#   dependencies: {
#     ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
# ```
flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

target 'my_crm' do
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()

  pod 'Firebase', :modular_headers => true
      pod 'FirebaseCore', :modular_headers => true
      pod 'GoogleUtilities', :modular_headers => true
      $RNFirebaseAsStaticFramework = true

  use_react_native!(
    :path => config[:reactNativePath],
    # Hermes is now enabled by default. Disable by setting this flag to false.
    # Upcoming versions of React Native may rely on get_default_flags(), but
    # we make it explicit here to aid in the React Native upgrade process.
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    # Enables Flipper.
    #
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
    :flipper_configuration => flipper_config,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

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

  post_install do |installer|
    react_native_post_install(
      installer,
      # Set `mac_catalyst_enabled` to `true` in order to apply patches
      # necessary for Mac Catalyst builds
      :mac_catalyst_enabled => false
    )
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

解决方法

这种错误通常是CocoaPods仓库缓存的Podspec文件损坏导致的,按以下步骤处理:

方法1:清理损坏的Podspec并更新仓库

  • 删除损坏的Podspec文件:
    rm /Users/apple/.cocoapods/repos/trunk/Specs/0/b/5/PromisesObjC/2.3.1/PromisesObjC.podspec.json
    
  • 更新CocoaPods仓库:
    pod repo update trunk
    
  • 回到项目iOS目录重新执行pod install

方法2:彻底清理缓存后重新安装

如果方法1无效,尝试完全清理缓存:

  • 删除本地CocoaPods trunk仓库:
    rm -rf ~/.cocoapods/repos/trunk
    
  • 清理项目的Pods目录和锁文件:
    cd ios && rm -rf Pods Podfile.lock
    
  • 重新更新仓库并安装依赖:
    pod repo update trunk
    pod install
    

方法3:指定稳定版本的PromisesObjC

若上述方法仍有问题,可在Podfile中明确指定一个稳定版本的PromisesObjC,避免拉取损坏的版本:
在target 'my_crm' do代码块内添加:

pod 'PromisesObjC', '2.2.0'

添加后执行pod install


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 00:17:33