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

创建React应用失败求助:缓存清理与Node更新后仍报错

解决create-react-app创建项目时的FETCH_ERROR超时问题
  • 切换npm国内镜像源
    默认npm官方源在国内访问易出现超时,切换到国内稳定镜像:

    npm config set registry https://registry.npmmirror.com/
    

    完成后重新执行创建命令:

    npx create-react-app projectName
    

    后续如需切回官方源,执行:

    npm config set registry https://registry.npmjs.org/
    
  • 调整npm网络超时时间
    增大npm的超时阈值,给包下载足够时间:

    npm config set fetch-retry-mintimeout 20000
    npm config set fetch-retry-maxtimeout 120000
    

    设置后再次尝试创建项目。

  • 清理npx缓存并强制使用最新版本
    清除npx本地缓存,避免使用旧版create-react-app导致的问题:

    npx clear-npx-cache
    npx create-react-app@latest projectName --use-npm
    
  • 手动初始化项目并安装依赖
    若上述方法无效,可手动搭建项目结构:

    1. 创建项目文件夹并初始化npm:
      mkdir projectName && cd projectName
      npm init -y
      
    2. 手动安装核心依赖:
      npm install react react-dom react-scripts cra-template --save --save-exact
      
    3. 在package.json中添加启动脚本:
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
      }
      
    4. 创建public和src目录,添加cra-template的默认基础文件(如index.html、App.js等)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 18:40:15