React: deploying your app to Heroku

k w
2 min readFeb 23, 2020

--

Recently when I was deploying my project to Heroku I stumbled upon an “Application Error”. Finally, I was able to resolve the problem. Below, you can find my path to my successful deployment.

An application error occurred after pushing to heroku remote copy of my repository.

Before deploying log into your Heroku account from terminal:

[kw ~]$ heroku login[…]Logging in… doneLogged in as youremail@gmail.com

The next step is to run:

 heroku create

This command will generate our domain for deployment.

After that step, add heroku as remote origin to your repository by running:

git remote add heroku https://git.heroku.com/desolate-temple-20082.gitCheck if heroku was added by running git remote -v in your terminal. After that you can run: git push heroku 

Your master branch is pushed to heroku.

To successfully deploy your application build with React, you should be aware of those things:

  1. If your .gitignore file contains build files like public/bundle.js and public/bundle.js.map, you will get an error while deploying. Before deploying, create a deploy branch and add build files.
git add -f public/bundle.js public/bundle.js.map
git commit — allow-empty -m ‘Adding build files’

You are ready to push your local “deploy” branch to the “master” branch on heroku.

git push --force heroku deploy:master

2. Update dependencies. I was missing express dependency.

{
“name”: “myapp”,
“version”: “1.0.0”,
“description”: “”,
“main”: “server.js”,
“scripts”: {
“test”: “echo \”Error: no test specified\” && exit 1",
“start”: “node server”,
“start-dev”: “webpack -w & nodemon server.js”},
“author”: “”,
“license”: “ISC”,
“dependencies”: {
“express”:”*”, // <------------- this one was missing!!!
“react”: “¹⁶.12.0”,
“react-dom”: “¹⁶.12.0”,
“react-redux”: “⁷.1.3”,
“react-router-dom”: “⁵.1.2”,
“redux”: “⁴.0.5”,
“redux-logger”: “³.0.6”,
“redux-thunk”: “².3.0”},
“devDependencies”: {
“@babel/core”: “⁷.8.3”,
“@babel/preset-env”: “⁷.8.3”,
“@babel/preset-react”: “⁷.8.3”,
“babel-loader”: “⁸.0.6”,
“babel-preset-react-native”: “⁴.0.1”,
“webpack”: “⁴.41.5”,
“webpack-cli”: “³.3.10”}
}

--

--

No responses yet