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

Ubuntu 22.04环境下npx create-react-app执行中断失败求助

解决npx create-react-app在Ubuntu 22.04 VPS上安装失败的问题

针对你在Ubuntu 22.04 VPS上使用Node.js v20.12.2和npm 10.5.0执行npx create-react-app myapp时出现的安装中断问题,试试以下几种解决方案:

  • 清理缓存
    缓存损坏是这类安装失败的常见原因,先清理npm和npx的缓存:

    npm cache clean --force
    npx clear-npx-cache
    

    清理完成后重新执行npx create-react-app myapp。

  • 指定稳定版本的create-react-app
    最新版create-react-app可能和Node.js v20存在兼容性问题,尝试指定一个经过验证的稳定版本:

    npx create-react-app@5.0.1 myapp
    
  • 排查网络与源的问题(VPS环境重点)

    • 测试当前npm源的连通性:执行npm ping,如果响应慢或失败,切换到国内镜像源:
      npm config set registry https://registry.npmmirror.com/
      
    • 确认VPS的防火墙/安全组规则允许443端口的出站请求,npm安装依赖需要通过HTTPS访问包仓库。
  • 手动初始化项目(兜底方案)
    如果自动安装始终失败,手动完成初始化步骤:

    1. 创建项目目录并进入:
      mkdir myapp && cd myapp
      
    2. 初始化package.json:
      npm init -y
      
    3. 手动安装所需依赖:
      npm install --save-exact react react-dom react-scripts cra-template
      
    4. 在package.json的scripts字段中添加以下命令:
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
      }
      

    完成后执行npm start即可启动项目。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 14:55:02