Heroku ENOENT: no such file or directory, stat '/app/build/index.html'
dist folder is ignored. therefore heroku returns this error. When you list your application files in heroku, you can see it is missing.
How to list folder/files in heroku
- run heroku run bash in command line inside of your app folder
- type dir and enter. then you will see the list of folders and files
First, don't use PWD. Just use __dirname. It works on Heroku exactly as it works anywhere else. Using PWD makes your app more brittle if you, for instance, execute a binary from a non-local directory.
Second, the reason that file doesn't exist on Heroku is likely because you've added it to your .gitignore file or generally haven't checked it into git. You can see this from the color coding of your editor - all of the files checked into git are white, the ones ignored are gray (like the node_modules directory and build/bundle). Your index file is red (not white like the checked-in files). So when you git push heroku master
, those files you're referencing don't exist.
Finally, the reason ENOENT says /app/build is just because your root/home directory on Heroku is /app. Never build apps that are locked into an absolute file structure; just use relative paths (otherwise, your app will break if you even move it to another directory on your local machine).
app.get('*', function (req, res) {
const index = path.join(__dirname, 'build', 'index.html');
res.sendFile(index);
});