Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my Flask app being detected as node.js on Heroku

I recently made some changes to the structure of my Flask app hosted on heroku and now heroku has decided to detect it as a Node.js app intead of a Python app. My application uses both python (Flask) for the backend api and javascript for the front end.

The changes I made included integrating npm and bower into my application to streamline the javascript development of the app.

like image 527
KhalilRavanna Avatar asked Nov 24 '13 04:11

KhalilRavanna


People also ask

How do I put Flask app on Heroku?

Deploying Flask App on Heroku STEP 1 : Create a virtual environment with pipenv and install Flask and Gunicorn . STEP 2 : Create a “Procfile” and write the following code. STEP 3 : Create “runtime. txt” and write the following code.

Can you use Flask with Heroku?

In this tutorial, you'll create a Python Flask example application and deploy it using Heroku, making it publicly available on the web. Heroku removes much of the infrastructure burden related to building and running web applications, allowing you to focus on creating an awesome app.

Why does my app fail to detect a Buildpack?

Resolution. This error message means that Heroku was unable to automatically detect the type of app you're trying to deploy: Ruby, Node, Python, PHP, Java, etc. We look for signatures for each language we support (like a pom. xml file or package.

Can Flask be used with node js?

It is possible to connect flask web application from node. js.


2 Answers

The problem was introduced when I added a package.json to my root directory when I started using npm. It seems that the build detection script runs the nodejs detection first (here) which leads to this code: if [ -f $1/package.json ]; then echo "Node.js" && exit 0 executing and Heroku thinks it's a nodejs app and exits before the python detection has a chance to run.

To solve this I had to manually tell Heroku that I wanted a python build using this command

heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-python.

like image 187
KhalilRavanna Avatar answered Sep 19 '22 08:09

KhalilRavanna


The package.json file is causing Heroku to detect it as a node.js app. To prevent this, add the file name to a .slugignore file:

echo 'package.json' >> .slugignore
git add .slugignore

.slugignore is like .gitignore. It resides in the root directory of your repository and should contain a list of filenames and wildcard patterns. The matching files remain in your git repository, but are deleted from the slug after you push to Heroku. The deletion occurs before the buildpacks run, so the node.js buildpack won't find package.json and the app won't be misidentified as a node.js app.

like image 25
drs Avatar answered Sep 18 '22 08:09

drs