Search code examples
reactjsherokudeploymentstrapi

Getting Heroku H10 Error when trying to deploy Strapi, MongoDB Atlas


So I've thoroughly followed the Docs for both Strapi and Heroku (with MongoDb Atlas already connected to Strapi), and I might have missed something important. When I deploy the app, the site loads for a bit then crashes. The heroku logs --tail command shows this:

2020-05-08T14:41:59.625984+00:00 app[web.1]: (node:23) Warning: Accessing non-existent property 'findOne' of module exports inside circular dependency
2020-05-08T14:41:59.626067+00:00 app[web.1]: (node:23) Warning: Accessing non-existent property 'remove' of module exports inside circular dependency
2020-05-08T14:41:59.626134+00:00 app[web.1]: (node:23) Warning: Accessing non-existent property 'updateOne' of module exports inside circular dependency
2020-05-08T14:42:04.000000+00:00 app[api]: Build succeeded
2020-05-08T14:42:29.627137+00:00 app[web.1]: [2020-05-08T14:42:29.626Z] debug ⛔️ Server wasn't able to start properly.
2020-05-08T14:42:29.627879+00:00 app[web.1]: [2020-05-08T14:42:29.627Z] error Error connecting to the Mongo database. Server selection timed out after 30000 ms
2020-05-08T14:42:29.640717+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-05-08T14:42:29.640989+00:00 app[web.1]: npm ERR! errno 1
2020-05-08T14:42:29.641812+00:00 app[web.1]: npm ERR! back-end-4@0.1.0 start: `strapi start`
2020-05-08T14:42:29.641895+00:00 app[web.1]: npm ERR! Exit status 1
2020-05-08T14:42:29.641997+00:00 app[web.1]: npm ERR!
2020-05-08T14:42:29.642078+00:00 app[web.1]: npm ERR! Failed at the back-end-4@0.1.0 start script.
2020-05-08T14:42:29.642155+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-08T14:42:29.649687+00:00 app[web.1]: 
2020-05-08T14:42:29.649822+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-05-08T14:42:29.649879+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-05-08T14_42_29_643Z-debug.log
2020-05-08T14:42:29.758124+00:00 heroku[web.1]: State changed from starting to crashed

2020-05-08T14:42:30.872518+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hidden-headland-71392.herokuapp.com request_id=2eb6e39a-875b-4b2c-91cd-3b2bdd914561 fwd="81.128.178.133" dyno= connect= service= status=503 bytes= protocol=https
2020-05-08T14:42:31.888706+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=hidden-headland-71392.herokuapp.com request_id=d96ec78a-83ea-48ca-b576-0ad62d0a15da fwd="81.128.178.133" dyno= connect= service= status=503 bytes= protocol=https

My server.json files in all 3 folder, development , production and staging are as follows:

{
  "host": "${process.env.HOST || '0.0.0.0'}",
  "port": "${process.env.PORT || 1337}",
  "production": true,
  "proxy": {
    "enabled": false
  },
  "cron": {
    "enabled": false
  },
  "admin": {
    "autoOpen": false
  }
}

I'm unsure about the Procfile, as it stands its a file in my base directory with no extension but with the line:

 web: node strapi start

And for reference my package.json looks like this:

{
  "name": "back-end-4",
  "private": true,
  "version": "0.1.0",
  "description": "A Strapi application",
  "scripts": {

    "develop": "strapi develop",
    "start": "strapi start",
    "build": "strapi build",
    "strapi": "strapi"
  },

And my database.json file looks like this:

{
  "defaultConnection": "default",
  "connections": {
    "default": {
      "connector": "mongoose",
      "settings": {
        "uri": "${process.env.DATABASE_URI}",
        "database": "${process.env.DATABASE_NAME}"
      },
      "options": {
        "ssl": true
      }
    }
  }
} 

Solution

  • FWIW - I had similar issues. I thought I had whitelisted all IPs on Mongodb but hadn't. This step isn't included in the video referenced above and - based on the output logged to your console - I'd guess you're having the same issue.

    This setting can be found in Mongodb under Security > Network Access > Add IP Address > If you use 0.0.0.0/0 it will whitelist anything Heroku throws at it.