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

如何将存放在子目录的create-react-app项目部署到Heroku

当前仓库结构参考:
仓库结构截图1
仓库结构截图2

App not compatible with buildpack报错核心原因是mars/create-react-app-buildpack默认读取仓库根目录的package.json文件,项目放在/dashboard子目录时无法识别到有效React项目结构。

解决方案

方案1:将dashboard目录移动至仓库根目录(适配Heroku部署)

操作步骤如下:

  • 打开终端,定位到本地仓库根目录,执行命令移动文件:
    git mv dashboard/* .
    # 若dashboard目录下有.gitignore等隐藏文件,额外执行
    git mv dashboard/.gitignore ./
    # 删除空的dashboard目录
    git rm -r dashboard
    
  • 检查根目录下是否存在package.json,确认文件内scripts字段的build、start命令配置正常
  • 提交改动到GitHub:
    git add .
    git commit -m "move React app to root directory"
    git push
    
  • 进入Heroku控制台对应项目的设置页,移除之前配置的自定义buildpack,重新选择官方Node.js buildpack或mars/create-react-app-buildpack,触发重新部署即可。

方案2:使用Netlify部署子目录项目(无需改动仓库结构)

操作步骤如下:

  • 登录Netlify控制台,点击「Add new site」→「Import an existing project」,绑定对应的GitHub仓库
  • 在部署配置页填写以下参数:
    • Base directory:dashboard
    • Build command:npm run build
    • Publish directory:dashboard/build
  • 点击「Deploy site」等待部署完成即可,后续代码推送至GitHub会自动触发部署。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.23 23:57:03