Crash & Burn: Some tips to solve error H10 while deploying your app to Heroku

Pato Montecchiarini
3 min readJul 11, 2020

Recently I’ve deployed my first app in Heroku. My app ran locally with no problems, and deployment on Heroku was successful, but when I tried to actually open the app I got an “Application Error” with no info on the logs other than it was H10.

Now H10 type errors can be caused by a variety of things. In this article, I will walk you through some of the steps I took in order to find what was the cause of the error in my app.

These are some items to check before you deploy:

  1. Create a Procfile. You can do that by running touch Procfile in the command. The Procfile provides Heroku with instructions on how to run your app, so on it, since my app was built with Node Js I typed:

web: node server/index.js

Be sure to check your index path or it won't work.

2. Check that you have set up the PORT number so that Heroku will be able to listen to the one it assigns to the app. You can do that by setting the PORT variable to:

const PORT = process.env.PORT || 3000 (or whatever your local port is)

This way you’ll allow Heroku to use the PORT it assigned the app when running online, but if it’s running locally it will listen to the port you have assigned it.

You can find this and all the steps to deploy your first app in this great video tutorial.

If you checked al this items but are still getting “Application Error”, run the following command:

heroku logs — tail -a YOUR_APP_NAME

(there is a space between logs and tail, and a double dash before tail)

By running this command you will see a much detailed error log. In my case personally, I had ERROR: can’t find module ‘dotenv’. If you are having trouble with other modules, maybe you need to install them. But in this case, the reason is different: dotenv is a module that loads environment variables from a .env file into the process. This .env file must always be on your .gitignore for security reasons. And because of that, the file is not being uploaded. Basically, dotenv is looking for the .env file, which exists locally but not on the remote repository (GitHub).

The way I solved this issue was by defining an environment variable called NODE_ENV and set its value to “production”. You can do this on Windows by typing on your terminal:

set NODE_ENV=production

For Linux it’s:

export NODE_ENV=production

Once you’ve defined the production environment you can check that dotenv won’t be referenced while in production. Something like:

if (process.env.NODE_ENV !== ‘production’) { require(‘dotenv’).config({ path: ‘variables.env’}) }

Be sure to check your package.json file to make sure dotenv is under “devDependencies” and not “dependencies” so Heroku will know it’s not needed in production.

And that’s pretty much it. That’s what got my app running after hours of research. This article is actually a compendium of several pieces of advice and articles on the subject.

Hope it helps! And good luck deploying. 😉

--

--

Pato Montecchiarini

I’m a web & mobile developer. Love all CSS related things. Coding in JS and Dart.