TransWikia.com

NestJS Application build on Heroku crashes because of TypeOrmModule with no precise error message

Stack Overflow Asked by Armen Vardanyan on November 12, 2021

I have a working application built on NestJS, which is deployed on a Heroku server. It used to work, until recently every build I do crashes with no good reason. I did some trials, and discovered that the app works when the TypeOrmModule is not included in the AppModule imports, But obviously it is unusable without the database. Here is how the AppModule config looks like:

const databaseUrl = process.env.DATABASE_URL;
@Module({
  imports: [
    TypeOrmModule.forRoot(databaseUrl ? {
      type: 'postgres',
      url: databaseUrl,
      entities: [__dirname + '/**/*.entity{.ts,.js}'],
      synchronize: true,
   } : {
      // configuration for local development
   }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

I have checked and the databaseUrl is being correctly loaded from the environment URL. This is not a stripped showcase example, this is literally what I deploy to Heroku – I have removed all other modules to understand where the problem was coming from. If I remove the TypeOrmModule now the app will not crash. Here is the unhelpful log that heroku provides me upon crash:

07/08/2020, 12:09:13 PM [NestFactory] Starting Nest application…
2020-07-08T12:09:13.300817+00:00 app[web.1]: [Nest] 23
07/08/2020, 12:09:13 PM [InstanceLoader] TypeOrmModule dependencies initialized +76ms
2020-07-08T12:09:13.301462+00:00 app[web.1]: [Nest] 23
07/08/2020, 12:09:13 PM [InstanceLoader] AppModule dependencies initialized +1ms
2020-07-08T12:09:13.416093+00:00 heroku[web.1]: Process exited with status 0
2020-07-08T12:09:13.463362+00:00 heroku[web.1]: State changed from starting to crashed
2020-07-08T12:09:13.463362+00:00 heroku[web.1]: State changed from starting to crashed

The build before the app start has been successful indicated in the same log. I have been truly at a loss here for more than a month.

One Answer

You may try this one in your main.ts to get log for such case:

process.on('uncaughtException', (err) => {
   Logger.warn(err, 'LOGGER', false);
});

If not enough, you may add other events for debugging by referencing here:

https://nodejs.org/api/process.html#process_process_events

And please check your tsconfig.json file If you have any migrations module and target should be like this one:

"target": "es2015",
"module": "CommonJS",

And one last thing: Make sure your database name matches with TypeORM config

Answered by Semyonic on November 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP