Deploying to Heroku

Has anyone else run into trouble trying to do this? I can deploy with heroku local web fine but deploying to heroku and the app crashes every time. This is infuriating

Iā€™ve encountered hiccups with it before.

Can you share the relevant bits? Iā€™m happy to help troubleshoot :slight_smile:

Hey, is your code on Github? In that case you should be able to just pull it in. Make sure your port is set correct.

I really donā€™t understand. I deployed an app successfully a few days ago, although it took a while. Iā€™m pretty sure Iā€™ve done everything 100% the same this time and itā€™s failing every time.

I basically have a build setup where I run npm build to build all my files into a dist/ directory and then I push everything to git and deploy to heroku with git push heroku master. At this point if I run heroku local web it works fine. But after deploying to heroku the application has an error everytime I open it: ā€œApp crashedā€ method=GET. Itā€™s detecting itā€™s a node app and running npm start which babel-node starts my server file. But I guess something in the above isnā€™t working.

Iā€™ve checked the express port, itā€™s listening on process.env.PORT. Iā€™ve checked the dependencies Iā€™m including. I really donā€™t know why itā€™s not working.

Do the logs give any information?

Your app is more complex than anything Iā€™ve done before, but looking at the source code - I wonder if there is some git deployment issue arising from the build pipeline you have? Like, maybe the dist folder gets cached and updates in weird ways when you make changes in src? That might explain why the first deployment worked but subsequent ones didnā€™t? (Obviously just spitballing, here!)

hang on I might have found itā€¦

T_T

Okay so I didnā€™t quite figure it out but I reduced it to Heroku is having an issue loading values from a .env file I have in my project root. I havenā€™t run into this issue before? My server file and routes inside a routes folder are both trying to access some values in .env. Any idea how I should config this so it works when I deploy to Heroku? I am trying to just their cli tool instead of their site, btw.

Have you set the appropriate config variables in Heroku?

I think there is a way to conditionally load the .env depending on whether the environment is ā€˜productionā€™ or ā€˜developmentā€™. Iā€™ve never done it myself, but I think you can use NODE_ENV (Heroku defaults NODE_ENV to ā€˜productionā€™ when you deploy).

Not sure if this helps, but I found this trying to find more to do with the production environment side of things:

Just got it working finallyā€¦ yes I had to load all the .env values directly and then be sure I updated my callback URLs correctly everywhere. For some reason I wasnā€™t able to load them successfully using dotenv although I have done that beforeā€¦ not clear on why but just happy to see the thing deployed and running now after 4 some hours of my mind melting trying to figure it outā€¦

Anywayā€¦ now we can all trade books together I pray you donā€™t find any bugs

Btw thanks for mentioning the logs I didnā€™t know you could get more info than the logs displaying on herokuā€™s website. Displaying the logs from the command line led me to the error about the .env file and then gradually to the solution.

Thanks everyone for such quick replies earlier!

1 Like

Hey am also having issues. after deployind i get this error; Error waiting for process to terminate: No child processes

Although Iā€™m (a little) surprised that dotenv didnā€™t work, the point of having ENV variables in Heroku separated from your git-based code is that itā€™s generally good practice not to have them in git at all - this is a common place to store access keys, tokens, passwords and the like.