I am trying to deploy MERN website in heroku but getting following error:
"ENOENT: no such file or directory, stat '/app/client/build/index.html'"
I have ran the project locally, and everything is working fine. I have added the following in package.json:
"heoku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
also here is the code in my 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.");
});
}
It should create react build
folder by running npm run build
but I think heroku-postbuild
command is not working.
I misspelled heroku
to heoku
so the actual command in package.json should be:
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"