2

I'm getting a Heroku H20 error (app boot timeout) followed by a H10 error (Web process failed to bind to $PORT within 60 seconds of launch)

My starter svelte project is using sirv in package.json:

{
  "name": "clicker",
  "version": "0.0.1",
  "scripts": {
    "build": "rollup -c",
    "dev": "rollup -c -w",
    "start": "sirv public"
  },
  "engines": {
    "node": "10.16.0",
    "npm": "6.13.1"
  },
  "devDependencies": {
    "rollup": "^1.12.0",
    "rollup-plugin-commonjs": "^10.0.0",
    "rollup-plugin-livereload": "^1.0.0",
    "rollup-plugin-node-resolve": "^5.2.0",
    "rollup-plugin-svelte": "^5.0.3",
    "rollup-plugin-terser": "^5.1.2",
    "svelte": "^3.0.0"
  },
  "dependencies": {
    "sirv-cli": "^0.4.4"
  }
}

I can't seem to figure out how to pass through the $PORT environment variable Heroku gives you. I've tried

"start": "sirv public --port $PORT"

The closest solution I have found refers to the fact that Heroku dynamically assigns your app a port, but all solutions I'm finding refer to using process.env.port in node, but I can't seem to figure out how to use it with sirv in my package.json file. Isn't it basically running 'sirv public' on a command line? So I can't just use process.env.port there since that's for accessing the port variable in code...

Heroku Logs

2019-12-02T07:54:26.210322+00:00 app[web.1]: Your application is ready~! �
2019-12-02T07:54:26.210323+00:00 app[web.1]:
2019-12-02T07:54:26.210377+00:00 app[web.1]:   - Local:      http://localhost:19516
2019-12-02T07:54:26.210621+00:00 app[web.1]:
2019-12-02T07:54:26.210624+00:00 app[web.1]:  LOGS
2019-12-02T07:54:26.210625+00:00 app[web.1]:
2019-12-02T07:55:08.914191+00:00 heroku[router]: at=error code=H20 desc="App boot timeout"
2019-12-02T07:55:24.799059+00:00 heroku[web.1]: State changed from starting to crashed
2019-12-02T07:55:24.713988+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2019-12-02T07:55:24.714032+00:00 heroku[web.1]: Stopping process with SIGKILL
2019-12-02T07:55:24.782218+00:00 heroku[web.1]: Process exited with status 137
2019-12-02T08:02:13.343213+00:00 heroku[router]: at=error code=H10 desc="App crashed"

Any ideas?

D T
  • 93
  • 1
  • 4

2 Answers2

2

Create an .env file (add to .gitignore) with contents:

HOST=localhost
PORT=5000

package.json start command:

{
  "start": "sirv public --host $HOST --port $PORT"
}

When running locally for development execute:

heroku local

This will pickup your env vars from .env

In production, Heroku will provide $HOST and $PORT

$HOST can probably be replaced with hard-coded 0.0.0.0 if desired:

Why is my Node.js app crashing with an R10 error?

cdock
  • 850
  • 9
  • 15
0
By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the sirv commands in package.json to include the option --host 0.0.0.0.

I added this to my package.json and it is successfully getting fully up on heroku!

D T
  • 93
  • 1
  • 4