我正在尝试在 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.");
});
}
它应该通过运行 build
创建 react npm run build
文件夹,但我认为 heroku-postbuild
命令不起作用。
答案 0 :(得分:1)
我将 heroku
拼错为 heoku
,因此 package.json 中的实际命令应该是:
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"