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

React项目部署Vercel报错:public目录缺失index.html

解决React项目在Vercel构建时找不到index.html的问题

错误核心原因

构建日志明确提示Could not find a required file. Name: index.html, Searched in: /vercel/path0/public,说明Vercel在项目的public目录下找不到index.html文件——这是React项目构建的必备文件,create-react-app默认会生成它。

具体解决步骤

  • 检查本地项目结构
    先看你本地的React项目根目录,确认有没有public文件夹,里面是不是真的有index.html。大概率是你误删了这个文件,或者把文件夹名拼错了(比如写成Public、pubic,注意必须是小写的public)。

  • 恢复/修正文件
    如果public文件夹或index.html丢了,直接重新创建:

    1. 在项目根目录新建public文件夹
    2. 里面新建index.html,粘贴以下默认内容:
      <!DOCTYPE html>
      <html lang="en">
        <head>
          <meta charset="utf-8" />
          <meta name="viewport" content="width=device-width, initial-scale=1" />
          <meta name="theme-color" content="#000000" />
          <meta name="description" content="Web site created using create-react-app" />
          <title>React App</title>
        </head>
        <body>
          <noscript>You need to enable JavaScript to run this app.</noscript>
          <div id="root"></div>
        </body>
      </html>
      

    如果只是文件名/文件夹名错了,改成正确的public和index.html就行。

  • 确认Vercel的项目根目录配置
    有时候Vercel没找对项目根目录。进入你的Vercel项目,打开「Settings」→「Build & Development Settings」,检查「Root Directory」是不是指向你的React项目所在的文件夹(比如你的React项目在仓库的my-app子目录里,就把Root Directory设为my-app)。

  • 重新触发构建
    把修复后的代码提交并推送到GitHub的main分支,然后去Vercel项目页面点「Redeploy」按钮,重新构建即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 15:55:27