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

React Native应用初始化报错:无法在npm仓库找到react-native包

React Native init 报错找不到react-native包的解决方法

执行npx react-native init doggo --verbose时遇到以下报错:

debug Installing template from react-native@latest
yarn init v1.22.19
warning The yes flag has been set. This will automatically answer yes to all questions, which may have security implications.
success Saved package.json
✨ Done in 0.03s.
yarn config v1.22.19
success Set "nodeLinker" to "node-modules".
✨ Done in 0.03s.
yarn add v1.22.19
info No lockfile found.
[1/4] 🔍 Resolving packages...
error Couldn't find package "react-native" on the "npm" registry.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
error Installing pods failed. This doesn't affect project initialization and you can safely proceed.
However, you will need to install pods manually when running iOS, follow additional steps in "Run instructions for iOS" section.

本地环境配置:

  • npm registry: https://registry.npmjs.org/
  • yarn registry: https://registry.yarnpkg.com
  • npx react-native版本: 12.3.6

以下是可行的解决步骤:

  • 清除yarn缓存,解决缓存损坏导致的解析异常:

    yarn cache clean
    

    清除后重新执行初始化命令。

  • 指定具体稳定版本初始化,避免latest版本的解析问题:

    npx react-native init doggo --version 0.72.6 --verbose
    

    可根据需求替换为其他React Native稳定版本。

  • 强制使用npm作为包管理器,绕开yarn的解析问题:

    npx react-native init doggo --package-manager npm --verbose
    
  • 升级yarn到最新稳定版,解决版本兼容性问题:

    yarn set version stable
    

    升级完成后重新执行初始化。

  • 手动补装react-native包:

    1. 进入已创建的项目目录:cd doggo
    2. 手动添加react-native包:yarn add react-native@latest
    3. 后续iOS环境需手动执行cd ios && pod install完成依赖安装。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 10:15:06