I have just seen your question. Recently I also worked on a similar kind of project personally.

In my case, I deployed them separately. First I deployed FLASKApi to Heroku referring to this youtube video and then I deployed my react js app

For my reactjs app deployment, I referred to this youtube video

Hope those videos help you too :)

Answer from tata_nukala on Stack Overflow
๐ŸŒ
Medium
medium.com โ€บ geekculture โ€บ a-complete-guide-to-building-and-deploying-your-own-website-with-react-flask-and-heroku-bc002dd94787
A Complete Guide to Building and Deploying Your Own Website with React, Flask and Heroku | by Ade Balogun | Geek Culture | Medium
October 25, 2021 - Weโ€™re almost done with our Flask server! In the root folder, weโ€™ll create a file called application.py which will produce our app from the factory created in __init__.py. We will also create a Procfile. Heroku will need these in order to host our server. Now for the client side. Building the frontend is made simple with the create-react-app package produced by the React team and Facebook.
๐ŸŒ
GitHub
github.com โ€บ SimmonsRitchie โ€บ flask-react-app
GitHub - SimmonsRitchie/flask-react-app: A dead simple Flask-React app that's easy to deploy to Heroku.
Ayushman Kumar's 'Deploy Python Flask App on Heroku' tutorial ... To install, clone this repo and cd into the root of the project. ... Activate the virtual environment. If you're using a Unix-based OS, run: ... For development, you may prefer ...
Starred by 6 users
Forked by 5 users
Languages ย  JavaScript 50.9% | SCSS 31.7% | Python 12.2% | HTML 5.0% | Shell 0.2% | JavaScript 50.9% | SCSS 31.7% | Python 12.2% | HTML 5.0% | Shell 0.2%
Discussions

How can I deploy a Flask API + create-react-app frontend to Heroku?
I don't know if that is what you are looking for, but I have an app like that that runs in a heroku dyno (the database being managed by the ClearDB add-on). The front end is a static React site hosted on github-pages making API calls to the heroku dyno. So I pretty much treat them as independent projects. I set all of this up by hand, which in hindsight was a mistake. I should have used Netlify or Now by ZEIT to deploy the front end. Be careful to configure your API in order to avoid CORS issues. Flask has a package for this . All of that said, I will also be following this thread to find out if there might be a smarter way I haven't thought about, because I am not at all convinced my way is the best way to do this. More on reddit.com
๐ŸŒ r/flask
3
15
June 19, 2019
python - having trouble deploying a flask api, react app to heroku - Stack Overflow
My file structure is as follows api --> where all my flask api is build src package.json I have successfully made a git repository out of the api and pushed it to my heroku account. I am having More on stackoverflow.com
๐ŸŒ stackoverflow.com
September 13, 2021
python - why can't i deploy react flask app on heroku? - Stack Overflow
However, i am having a difficult ... with the FLASK server deployed already.. Googled, came across some good resources but no luck on implementing any idea or how to go about it. Main issue is how can i tell heroku to npm run build or start react files? or even to deploy properly this application.... More on stackoverflow.com
๐ŸŒ stackoverflow.com
January 8, 2021
reactjs - How to create a deployment pipeline with React and Flask on Heroku? - Stack Overflow
Whenever I make a change in my ... directory into my Flask app, and then create a Blueprint for the React page (using this /build directory as the templates/static folder). Once I've copy/pasted this, I can commit to Github and deploy on Heroku.... More on stackoverflow.com
๐ŸŒ stackoverflow.com
December 23, 2020
๐ŸŒ
YouTube
youtube.com โ€บ watch
How To Deploy A Flask Rest API BackEnd And React FrontEnd To Heroku | Flask React Heroku | 2021 HD - YouTube
Hello Friends ๐Ÿ˜Š ๐Ÿ”” Subscribe & click that notification bell so you don't miss anything!In this video tutorial, we will learn how to deploy a simple Flask ba...
Published ย  June 16, 2021
๐ŸŒ
Reddit
reddit.com โ€บ r/flask โ€บ how can i deploy a flask api + create-react-app frontend to heroku?
r/flask on Reddit: How can I deploy a Flask API + create-react-app frontend to Heroku?
June 19, 2019 -

Currently I have built my app as a Flask API backend with React frontend in /client folder.

I run it locally by setting proxy: localhost:5000 in /client/package.json and running both react-scripts start and flask server. Then I visit localhost:3000, where the react app is served and everything works as expected.

How can I deploy this app to heroku?

๐ŸŒ
Miguel Grinberg
blog.miguelgrinberg.com โ€บ post โ€บ how-to-deploy-a-react--flask-project
How to Deploy a React + Flask Project - miguelgrinberg.com
March 29, 2020 - The Flask project now is able to serve both the React and Flask sides, so now all that is left is to deploy it like you would for a Flask only project. For example, you can use gunicorn or uWSGI. I assume that if you are using this method you are either creating a quick test, or else you are deploying to a managed platform such as Heroku. If instead you use this method on a server that you manage and you intend to run your application ...
Find elsewhere
๐ŸŒ
GitHub
github.com โ€บ neelsomani โ€บ react-flask-heroku
GitHub - neelsomani/react-flask-heroku: Simple bootstrapping code for a React frontend and Flask backend ready to deploy to Heroku.
April 24, 2020 - Simple bootstrapping code for a React frontend and Flask backend ready to deploy to Heroku. - neelsomani/react-flask-heroku
Starred by 16 users
Forked by 2 users
Languages ย  HTML 41.8% | JavaScript 32.3% | CSS 14.8% | Python 11.1% | HTML 41.8% | JavaScript 32.3% | CSS 14.8% | Python 11.1%
๐ŸŒ
GitHub
github.com โ€บ liranfar โ€บ flask-react-on-heroku
GitHub - liranfar/flask-react-on-heroku: small and basic flask app with react prepared for deployment on heroku
a onepage react app served by flask & sqlite/postgres db, deployed easily on heroku.
Starred by 16 users
Forked by 7 users
Languages ย  JavaScript 57.4% | CSS 24.9% | Python 11.8% | HTML 5.7% | Shell 0.2% | JavaScript 57.4% | CSS 24.9% | Python 11.8% | HTML 5.7% | Shell 0.2%
๐ŸŒ
YouTube
youtube.com โ€บ ssali jonathan
Build A Full-Stack Web Application with Flask And ReactJS - Part 16 Flask and React Heroku Deploy - YouTube
Hey there, This is part 16 of a series of videos in which we build a full stack web application using ReactJS and Python with Flask. This video targets anyon...
Published ย  August 27, 2021
Views ย  9K
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 69161071 โ€บ having-trouble-deploying-a-flask-api-react-app-to-heroku
python - having trouble deploying a flask api, react app to heroku - Stack Overflow
September 13, 2021 - I changed my folder structure but now again the api gets deployed but the react frontend doesn't. It gives me this error :The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. 2021-09-13T12:58:33.723Z+00:00 ... @AliNaji Check your routes or static file location you have set in flask app.
๐ŸŒ
Medium
medium.com โ€บ @banphlet4 โ€บ deploying-flask-react-project-to-heroku-afd0d52314e6
Deploying Flask-React Project to Heroku | by Nana Kwame Zoe | Medium
December 11, 2021 - Follow the installation guide on Flask to set up and install flask https://flask.palletsprojects.com/en/1.1.x/installation/. Clone the repository we would be using in this tutorial https://github.com/banphlet/Flask-Tensorflow.
๐ŸŒ
YouTube
youtube.com โ€บ arpan neupane
How to Deploy a Flask App to Heroku | Flask Heroku Deployment - YouTube
Hey guys! Welcome back, in this video, I will be showing you how to deploy a Flask website to Heroku. If you don't know what Heroku is, Heroku is a cloud-bas...
Published ย  May 16, 2021
Views ย  54K
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 65420931 โ€บ how-to-create-a-deployment-pipeline-with-react-and-flask-on-heroku
reactjs - How to create a deployment pipeline with React and Flask on Heroku? - Stack Overflow
December 23, 2020 - wsgi.py (Flask entry point) Procfile requirements.txt website --- frontend-app (submodule React app repo) --- build (compiled version of the React app using npm run build --- other directories --- __init__.py ... You can use multiple buildpacks: devcenter.heroku.com/articles/โ€ฆ. First, you need to build NodeJS (package.json must be in the root), then python
๐ŸŒ
DEV Community
dev.to โ€บ codemaker2015 โ€บ deploy-your-flask-app-on-heroku-1mab
Deploy your flask app on Heroku - DEV Community
September 18, 2022 - Leave the region and pipeline option as default. Login to the heroku cli using the following command ... Execute the commands listed on the Deploy tab to deploy your flask app on the Heroku cloud.
Top answer
1 of 2
9

So! It turns out Heroku support team was incorrect in their analysis of my application. My application is built in two different ways (one for production as well as for development). Using npm run start [see static/package.json] on local utilizes hot reloading and benefits from faster local changes via server.js. However, in a production environment, you want to use a compressed bundle.js file so my goal was to use npm run build:production [see static/package.json].

The issue I was running into was SyntaxError: expected expression, got '< bundle.js:1 in the console and it seemed to me that bundle.js wasn't loading at all. I listed a series of valid questions above on why I thought that might happen, but they all assumed that the main problem was an inability to run my react application at the same time as my flask application.

I was totally wrong. I didn't need to run server.js at all. The REAL reason that index.html and flask/python wasn't able to find my bundle.js and load the frontend on production was because of a mistake in the config.py file within flask which I never thought to post.

Flask has a very particular configuration that allows static_folder to be defined and template_folder. A while back I had swapped my static_folder for another directory while working on some image upload functionality. The reason I never caught it is because on local I run server.js for hot reloading so I never saw the compressed bundle.js file error out.

After fixing this mistake, I pushed to heroku and amazingly...it worked on the first try!

Here's the correct code that fixed it:

app = Flask(__name__, static_folder="./static/dist", template_folder="./static")

In closing whilst running a flask/react application on Heroku:

  • Use multi buildpacks (one for node, one for python).
  • Use your procfile to load only the flask side.
  • You need a package.json file in your root directory...even if you have another in your static folder like me.
  • Use webpack to compress your react code and serve it up in a compressed way.
  • Use render_template with flask to render the index.html file that holds you root div for react.
  • make sure all your dependencies for React are listed inside of actual "dependencies" instead of "devdepencies" otherwise Heroku will ignore them.

I really hope this helps someone! I was slamming my head against the wall for 2 weeks and it turned out to be a small obscure problem....isn't it always?

Additional resources: https://codeburst.io/creating-a-full-stack-web-application-with-python-npm-webpack-and-react-8925800503d9 While this is very simplified...it's what lead me to finding my bug so I'll post it here.

2 of 2
1

Your flask backend doesn't seem to be running on the same port as you forward your traffic too:

Starting gunicorn 19.6.0 Listening at: 0.0.0.0:13521 (4) 

app.all(/^\/api\/(.*)/, (req, res) => {
    proxy.web(req, res, { target: 'http://0.0.0.0:8081' });
});

Flask is listening on port 13521 (chosen randomly) but the /api/ routes are forwarded to port 8081. Instead, you should probably configure gunicorn to use a fixed port: http://docs.gunicorn.org/en/latest/settings.html#bind

๐ŸŒ
Medium
medium.com โ€บ @kharissaleah โ€บ deploying-a-bundled-flask-react-app-to-heroku-ff1c5ce2bc07
Deploying a bundled Flask/React app to Heroku | by Kharissa Leah | Medium
May 4, 2019 - The simplest way to deploy your Flask/React web application is to separately deploy your back-end and front-end to a service like Herokuโ€ฆ
๐ŸŒ
Reddit
reddit.com โ€บ r/flask โ€บ deploying a flask backend, react frontend app
Deploying A Flask Backend, React Frontend App : r/flask
September 21, 2017 - Now, once you've got an idea that demands a lot of data or data processing, that's when you make an API with Flask. Host it with a service like Heroku where you can store secret keys and the like without people seeing it. You can get the data from your React app by using an HTTP library - a popular one rn is Axios. The idea is you deploy these two things separately!
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ deploying-a-flask-application-to-heroku
Deploying a Flask Application to Heroku
December 4, 2019 - That way, Heroku knows which ones to provide for us, similar to how we install them locally when developing the app. To achieve this, we need to create a requirements.txt file with all of the modules: ... This way we end up with a requirements.txt file that contains the libraries we're using and their versions: Click==7.0 Flask==1.1.1 gunicorn==19.9.0 itsdangerous==1.1.0 Jinja2==2.10.1 MarkupSafe==1.1.1 Werkzeug==0.15.6