Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a Node module in a Django / Python app on Heroku

I have a fairly classic Python/Django app deployed to Heroku.

There's a pip package I want to use, django-mjml that itself relies on a Node.js module named mjml.

My question is how to combine the two? Doing npm init and npm install mjml created a node_modules directory in my root folder, and also the files: package.json and package-lock.json. I guess that's not really what I want?

Not sure how to proceed from here and any directions are appreciated!

like image 507
zerohedge Avatar asked Sep 02 '25 05:09

zerohedge


1 Answers

I haven't used that library, but you probably need to use multiple buildpacks:

  1. Set your main buildpack to heroku/python:

    heroku buildpacks:set heroku/python
    
  2. Add the heroku/nodejs buildpack:

    heroku buildpacks:add --index 1 heroku/nodejs
    
  3. Confirm that the Node.js buildpack will run first and the Python buildpack will run second with

    heroku buildpacks
    

Make sure you've got

  • a requirements.txt file (if you're using pip) or both Pipfile and Pipfile.lock (if you're using Pipenv) committed for your Python dependencies, and
  • a package.json file and either package-lock.json (if you're using npm) or yarn.lock (if you're usng Yarn) committed for the mjml dependency.

The package.json and package-lock.json you mention in your question should suffice for the Node.js dependencies, but they have to be committed, and you need to set the buildpacks before pushing.

like image 120
Chris Avatar answered Sep 04 '25 22:09

Chris