4
votes

I have a NestJS application with the CoreModule which exports an collection of the core services to all other modules. In core module i have dynamic module register HttpModule. I won't to register this module twice for import and export so i do the following:

const httpModule = HttpModule.register({
    timeout: Configuration.requestTimeoutMilliseconds
});

@Module({
    imports: [httpModule],
    providers: [
        ...
    ],
    exports: [
        httpModule,
        ...
    ]
})
export class CoreModule { }

When i start my app i see in InstanceLoader logs HttpModule dependencies registered twice:

enter image description here

What the proper way to export dynamic modules in general?

1

1 Answers

0
votes

You can do it like this.

@Module({
  imports: [
    HttpModule.register({
      timeout: Configuration.requestTimeoutMilliseconds,
    }),
  ],
  providers: [],
  exports: [HttpModule],
})
export class CoreModule {}

Makes sense to me because when you want to implement a dynamic module, you need to return module class as a module identifier in the module field.

There are examples of declaring dynamic modules on this page in documentation https://docs.nestjs.com/fundamentals/dynamic-modules#module-configuration