DEV Community

Cover image for Deploy Build-Only React Apps to Heroku

Deploy Build-Only React Apps to Heroku

Ileriayo Adebiyi on February 06, 2020

Today I had to deploy a React application to Heroku. I tried several methods and one of them required that I deployed the entire codebase since Her...
Collapse
 
morskibg profile image
morskibg • • Edited

Hi, Thank You very much! Just to mention, may be will be a good idea to add this to the App.js, for handling unknown paths.
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});

Collapse
 
xs005 profile image
Chris Sun •

Works pretty well, I tried to figure out this using several hours. Your solution is the best.

Collapse
 
ileriayo profile image
Ileriayo Adebiyi •

Hello Chris!
I'm excited to hear that this worked for you.
Thanks for letting me know.

Collapse
 
ristefront profile image
Riste •

Everything is OK need just to add in package.json "start:"node app" before push on heroku

Collapse
 
ileriayo profile image
Ileriayo Adebiyi •

Thanks for mentioning Riste.

Collapse
 
farcis profile image
farcis •

Nice hack!
I have applied your solution with docker app for heroku and works fine too
thanks a lot!!

Collapse
 
ileriayo profile image
Ileriayo Adebiyi •

Awesome!🚀

Glad to hear that this worked for you.

Collapse
 
drinfejzullahu profile image
drinfejzullahu •

Thank you, it works pretty well for me too.

Collapse
 
ileriayo profile image
Ileriayo Adebiyi •

Excited to hear that this worked for you!

Collapse
 
ileriayo profile image
Ileriayo Adebiyi •

Thanks for letting me know that this worked for you!

Collapse
 
colerau profile image
Cole Rau •

Thank you so much for writing this article. Your solution worked and I was able to deploy my app's production build to Heroku.

Collapse
 
ileriayo profile image
Ileriayo Adebiyi •

Happy to hear that you found this helpful!