I am currently facing an issue while implementing the @nestjs/typeorm
module with async configuration. In my app.module.ts
, I have the below setup:
@Module({
controllers: [
AppController,
],
exports: [ConfigModule],
imports: [
ConfigModule,
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (config: ConfigService) => {
console.log("config.getPostgresConfig(): ", config.getPostgresConfig());
return {
...config.getPostgresConfig(),
entities,
synchronize: true,
type: "postgres",
} as PostgresConnectionOptions;
},
}),
],
providers: [AppService],
})
export class AppModule {}
Although the console.log output seems correct, I am encountering the following error persistently:
2019-06-17T14:41:35.569358700Z [Nest] 45 - 06/17/2019, 2:41 PM [NestFactory] Starting Nest application...
2019-06-17T14:39:31.277686600Z at Object.next (/root/node_modules/tslib/tslib.js:114:57)
2019-06-17T14:41:35.740192700Z [Nest] 45 - 06/17/2019, 2:41 PM [TypeOrmModule] Unable to connect to the database. Retrying (1)... +170ms
2019-06-17T14:41:35.740666500Z Error: No connection options were found in any of configurations file.
2019-06-17T14:41:35.740704100Z at ConnectionOptionsReader.<anonymous> (/root/src/connection/ConnectionOptionsReader.ts:41:19)
I had planned for all configurations to be dynamically handled through the config service, so I am puzzled as to why it is requesting a config file and failing to establish a database connection.