【发布时间】:2021-09-22 11:23:42
【问题描述】:
我正在尝试在 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-postbuildcommand 不起作用。
【问题讨论】:
标签: node.js reactjs heroku create-react-app