title: NestJS Application build on Heroku crashes because of TypeOrmModule with no precise error message
body: <p>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 <code>TypeOrmModule</code> is not included in the <code>AppModule</code> imports, But obviously it is unusable without the database. Here is how the <code>AppModule</code> config looks like:</p>
  <pre class="lang-js prettyprint-override"><code>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 {}
  </code></pre>
  <p>I have checked and the <code>databaseUrl</code> 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 <code>TypeOrmModule</code> now the app <strong>will not</strong> crash. Here is the unhelpful log that heroku provides me upon crash:</p>
  <blockquote>
  <p>07/08/2020, 12:09:13 PM   [NestFactory] Starting Nest application...
  2020-07-08T12:09:13.300817+00:00 app[web.1]: [Nest] 23<br />
  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<br />
  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</p>
  </blockquote>
  <p>The build before the app start <strong>has been successful</strong> indicated in the same log. I have been truly at a loss here for more than a month.</p>