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

Mac下React Native初始化失败,寻求规避cdn.jsdelivr.net的方案

React Native初始化失败(libevent CDN封禁)解决方案

1. 无需依赖cdn.jsdelivr.net的替代配置

  • 用旧版React Native初始化项目
    React Native 0.71.x及更早版本的libevent podspec未使用cdn.jsdelivr.net,可指定版本创建项目:

    npx react-native@0.71.12 init AwesomeProject
    
  • 修改现有项目的libevent podspec
    若项目目录已生成,手动修改node_modules/react-native/third-party-podspecs/libevent.podspec中的source字段,替换为GitHub仓库地址:

    # 原内容
    s.source = { :http => 'https://cdn.jsdelivr.net/gh/libevent/libevent@release-2.1.12-stable/libevent.podspec' }
    # 修改后
    s.source = { :git => 'https://github.com/libevent/libevent.git', :tag => 'release-2.1.12-stable' }
    

    进入ios目录重新执行:

    pod install
    

2. 不受地区限制的React Native CocoaPods替代源

  • 替换CocoaPods默认源为国内镜像
    执行命令替换trunk源为清华镜像:

    pod repo remove trunk
    pod repo add trunk https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
    
  • 单独指定libevent的podspec来源
    在ios/Podfile中添加如下配置,直接从GitHub拉取libevent的podspec:

    pod 'libevent', :podspec => 'https://raw.githubusercontent.com/libevent/libevent/release-2.1.12-stable/libevent.podspec'
    

    之后执行pod install即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 18:15:06