Where does Heroku create the build folder? (getting 404 status error)

288 Views Asked by At

I'm getting a 404 (Not Found) error for my build/index.html file when I open my web app on Heroku. My Procfile is web node ./src/server/index.js.

src/server/index.js:

...
app.use(express.static(path.join(__dirname, "../build")))

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, '../build', 'index.html'))
})

File structure:

build/
├─ index.html
├─ manifest.json
public/
├─ index.html
├─ manifest.json
src/
├─ server/
│  ├─ index.js (Node.js + Express)
│  ├─ package.json
├─ App.tsx
├─ index.tsx (renders React App)
Procfile
package.json

Should my build folder be a new one created by Heroku, and if so, where should I have Heroku create it?

Heroku logs:

heroku[web.1]: Unidling
heroku[web.1]: State changed from down to starting
heroku[web.1]: Starting process with command `node ./src/server/index.js`   
app[web.1]: Server running on port 34747
heroku[web.1]: State changed from starting to up
heroku[router]: at=info method=GET path="/" host=myapp.herokuapp.com request_id=96b5064b-6558-46ec-b793-7de556c14da8 fwd="130.126.255.47" dyno=web.1 connect=0ms service=9ms status=404 bytes=412 protocol=https
app[web.1]: Error: ENOENT: no such file or directory, stat '/app/src/build/index.html'
1

There are 1 best solutions below

1
ahmed On

You can explore the heroku image by running a one-off Dyno:

heroku run bash

Then use standard Linux commands to disaply the connet and view files/directories (like ls, cd, etc...)