Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application error with Heroku after deployment

After having deployed my app with success I clicked on "Open app" and I see this error:

Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs --tail

Link with error https://fcrg.herokuapp.com/

But it does work correctly in localhost with yarn dev cli

package.json for backend app :

{
  "name": "site-web-france",
  "version": "1.0.0",
  "scripts": {
    "start": "node server.js",
    "heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build",
    "client": "cd client && yarn start",
    "server": "nodemon server.js",
    "dev": "concurrently --kill-others-on-fail \"yarn server\" \"yarn client\"",
    "dev:server": "cd client && yarn build && cd .. && yarn start",
    "start": "node server.js",
    "heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build"
  },
  "dependencies": {
    "body-parser": "^1.18.3",
    "express": "^4.16.3",
    "mongodb": "^3.1.1",
    "mongoose": "^5.2.6",
    "react-scripts": "^1.1.4"
  },
  "devDependencies": {
    "concurrently": "^3.5.0"
  }
}

I think this problem is because of "yarn", what do you think ?

tutorial followed : https://medium.freecodecamp.org/how-to-make-create-react-app-work-with-a-node-backend-api-7c5c48acb1b0

like image 803
crg Avatar asked Oct 16 '22 14:10

crg


1 Answers

Make sure that the application port is NOT hard-coded like:

app.listen(3000, ...)

It can cause problems with Heroku. Instead try using the environment variable PORT:

app.listen(process.env.PORT || 3000, ...)

Hope it helps!

like image 53
Ajay Avatar answered Oct 29 '22 21:10

Ajay