Search code examples
node.jstypescriptnpm

Nest.js Type 'DynamicModule' is not assignable to type 'ForwardReference' on nest-modules/mailer


I have an Nest.js application. I wanted to add MailerModule to my app using following link -> https://npm.taobao.org/package/@nest-modules/mailer

However, I just did the following steps:

First, npm install --save @nest-modules/mailer

Second I add app module mail config but it is giving an error here is my app.module.ts:

import { Module } from '@nestjs/common';
import { HandlebarsAdapter, MailerModule } from '@nest-modules/mailer';


@Module({
  imports: [
    MailerModule.forRootAsync({
      useFactory: () => ({
        transport: 'smtps://user@domain.com:pass@smtp.domain.com',
        defaults: {
          from:'"nest-modules" <modules@nestjs.com>',
        },
        template: {
          dir: __dirname + '/templates',
          adapter: new HandlebarsAdapter(), // or new PugAdapter()
          options: {
            strict: true,
          },
        },
      }),
    }),],
})
export class ApplicationModule {}

Now I can't compile because it is saying that :

TS2345: Argument of type '{ imports: DynamicModule[]; }' is not assignable to parameter of type 'ModuleMetadata'.   Types of property 'imports' are incompatible.     Type 'DynamicModule[]' is not assignable to type '(Type | DynamicModule | Promise | ForwardReference)[]'.       Type 'DynamicModule' is not assignable to type 'Type | DynamicModule | Promise | ForwardReference'.         Type 'DynamicModule' is not assignable to type 'ForwardReference'.           Property 'forwardRef' is missing in type 'DynamicModule'.


Solution

  • Perhaps check what version of nest you're using, this issue may be resolved in versions of nestjs 6+:

    https://github.com/nestjs/nest/issues/669