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

执行yarn add react-native@latest报错无法初始化React Native项目求助

解决方案

  • 升级Node.js版本
    最新版React Native最低要求Node.js 16.x版本,当前使用的14.1.0版本不符合兼容性要求,是报错的核心原因。推荐使用nvm管理Node版本,避免全局版本冲突,安装18.x LTS版本即可适配最新版RN:
    nvm install 18.17.0
    nvm use 18.17.0
    
  • 清理缓存并切换国内镜像源
    网络问题导致包拉取失败也会触发该报错,执行以下命令清理缓存并切换为国内镜像源即可解决:
    npm cache clean --force
    yarn cache clean
    npm config set registry https://registry.npmmirror.com/
    yarn config set registry https://registry.npmmirror.com/
    
  • 强制使用npm初始化项目
    若yarn本身存在配置问题,可在初始化时指定使用npm跳过yarn:
    npx react-native init MyApp --template react-native-template-typescript --npm
    
  • 指定兼容旧版RN初始化
    若暂时无法升级Node.js版本,可指定兼容Node14的RN版本进行初始化:
    npx react-native init MyApp --version 0.70.14 --template react-native-template-typescript@6.12.10
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.27 19:06:03