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.