equaliser
equaliser

Reputation: 171

NestJS Heroku Deploy H10

I deploy a NestJS Application to Heroku and get H10 Error

Log:

2020-05-07T13:12:51.967622+00:00 heroku[web.1]: State changed from starting to crashed

2020-05-07T13:15:14.556288+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=scalenode.herokuapp.com request_id=535e5643-26ad-4fbe-acf3-7f805c8c463c fwd="91.64.79.140" dyno= connect= service= status=503 bytes= protocol=https

Its stunning, because the Error comes because of GET Request. Node has been compiled successfully. I deployed via HerokuCli and Github. Both has the same result. But if I test it with HerokuCli locally with heroku local web, it works.

It does not seems to be a deployment error itself, its seems to be the route / cant be resolved so the app crashes. When I open the app in browser after successfully deploy, it seems to be a timeout.

Here is the Repo. I have a 'Hello World' string on / route. I cant find out whats wrong.

I use a Procfile for the instance, which seems to be fine:

web: node dist/main.js

EDIT:

I tried to have a static HTML Response and tried stable Node Version 12.x.

I dont get it

2020-05-07T14:22:40.862206+00:00 app[web.1]: [32m[Nest] 4   - [39m05/07/2020, 2:22:40 PM   [38;5;3m[RoutesResolver] [39m[32mAppController {}:[39m[38;5;3m +6ms[39m

2020-05-07T14:22:40.865503+00:00 app[web.1]: [32m[Nest] 4   - [39m05/07/2020, 2:22:40 PM   [38;5;3m[RouterExplorer] [39m[32mMapped {, GET} route[39m[38;5;3m +3ms[39m

2020-05-07T14:22:40.865886+00:00 app[web.1]: [32m[Nest] 4   - [39m05/07/2020, 2:22:40 PM   [38;5;3m[RoutesResolver] [39m[32mAuthController {}:[39m[38;5;3m +0ms[39m

2020-05-07T14:22:40.867140+00:00 app[web.1]: [32m[Nest] 4   - [39m05/07/2020, 2:22:40 PM   [38;5;3m[RouterExplorer] [39m[32mMapped {/auth/login, POST} route[39m[38;5;3m +2ms[39m

2020-05-07T14:22:40.867778+00:00 app[web.1]: [32m[Nest] 4   - [39m05/07/2020, 2:22:40 PM   [38;5;3m[RouterExplorer] [39m[32mMapped {/profile, GET} route[39m[38;5;3m +0ms[39m

2020-05-07T14:22:40.868162+00:00 app[web.1]: [32m[Nest] 4   - [39m05/07/2020, 2:22:40 PM   [38;5;3m[RoutesResolver] [39m[32mFilesController {/files}:[39m[38;5;3m +1ms[39m

2020-05-07T14:22:40.868999+00:00 app[web.1]: [32m[Nest] 4   - [39m05/07/2020, 2:22:40 PM   [38;5;3m[RouterExplorer] [39m[32mMapped {/files/upload, POST} route[39m[38;5;3m +0ms[39m

2020-05-07T14:22:40.873240+00:00 app[web.1]: [32m[Nest] 4   - [39m05/07/2020, 2:22:40 PM   [38;5;3m[NestApplication] [39m[32mNest application successfully started[39m[38;5;3m +5ms[39m

2020-05-07T14:22:42.000000+00:00 app[api]: Build succeeded

It doesnt work... i cant find more details in logs, nothing more concrete. What the hell is going wrong...

Upvotes: 1

Views: 1979

Answers (3)

Leo Bravo
Leo Bravo

Reputation: 1

In my case was to:

  1. Add a Procfile
  2. In the file, add: web: npm run start:prod

And have the script in package.json.

Follow this tutorial:

https://medium.com/weekly-webtips/deploying-a-nestjs-app-with-heroku-5fa84cb5b6c6

Upvotes: 0

Ogulcan Tümdoğan
Ogulcan Tümdoğan

Reputation: 111

Did you try setting heroku config variable NPM_CONFIG_PRODUCTION to false?

You can try this by going to your heroku dashboard -> settings -> reveal config vars, and then add the value above.

This error happens mainly because NestJS relies on some devDependencies in your project, and heroku removes devDependencies when building your Nest app if you're building in production mode. Setting NPM_CONFIG_PRODUCTION config to false would include all your dev dependencies in the Nest app's build process, just like building for a development environment. Alternatively, you can selectively move your nest related devDependencies to dependencies in package.json until the problem is gone.

Let me know if it works!

Upvotes: 1

Mariam V. Maldonado
Mariam V. Maldonado

Reputation: 31

In main.ts, have you tried changing the port number? To something like:

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

Since Heroku will try to use its own port. Maybe this could work too:

const port: number = parseInt(`${process.env.PORT}`) || 3000;
await app.listen(port);

Upvotes: 2

Related Questions