Heroku 错误 404,"ENOENT: no such file or directory, stat '/app/client/build/index.html'"

Heroku Error 404, "ENOENT: no such file or directory, stat '/app/client/build/index.html'"

我正在尝试在 heroku 中部署 MERN 网站,但出现以下错误:

"ENOENT: no such file or directory, stat '/app/client/build/index.html'"

我在本地有 运行 项目,一切正常。 我在 package.json 中添加了以下内容:

"heoku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"

也是我的server.js

中的代码
// Deployment
if (process.env.NODE_ENV === "production") {
  app.use(express.static(path.join(__dirname, "../client/build")));
  app.get("*", (req, res) =>
    // res.sendFile(path.resolve(__dirname, "../client", "public", "index.html"))
    res.sendFile(path.resolve(__dirname, "../client/build/index.html"))
  );
} else {
  app.get("/", (req, res) => {
    res.send("API IS RUNNING.");
  });
}

它应该通过 运行 npm run build 创建 react build 文件夹,但我认为 heroku-postbuild 命令不起作用。

我把 heroku 拼错成了 heoku 所以 package.json 中的实际命令应该是:

"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"