title: NestJS JwtModule.registerAsync() gives undefined at imports
body: <p>when I nest start the code, it gives follow error, what is the problem?</p>
  <p>I set ConfigModule as Gloabl, so I shouldn't need to import.</p>
  <p>If I missed any code, please tell me, I can post it here.</p>
  <p>I reference usage in <a href="https://github.com/nestjs/jwt" rel="nofollow noreferrer">NestJS Jwt package</a></p>
  <p>I previously use JwtModule.register() with hardcoded secrets and options, it works fine.</p>
  <pre><code>[Nest] 159128   - 02/27/2021, 6:27:15 PM   [ExceptionHandler] Nest cannot create the AuthModule instance.
  The module at index [2] of the AuthModule &quot;imports&quot; array is undefined.
  
  Potential causes:
  - A circular dependency between modules. Use forwardRef() to avoid it. Read more: https://docs.nestjs.com/fundamentals/circular-dependency
  - The module at index [2] is of type &quot;undefined&quot;. Check your import statements and the type of the module.
  </code></pre>
  <p>TyprOrmModule access the database just fine, it proves configService picks up environment variables in .env</p>
  <p>AppModule.ts:
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import { Module } from '@nestjs/common';
  import { AppController } from './app.controller';
  import { TypeOrmModule } from '@nestjs/typeorm';
  import { Connection } from 'typeorm';
  import { join } from 'path';
  import { UserModule } from './user/user.module';
  import { AuthModule } from './auth/auth.module';
  import { FormModule } from './form/form.module';
  import { InventoryModule } from './inventory/inventory.module';
  import { ConfigModule, ConfigService } from '@nestjs/config';
  
  
  @Module({
    imports: [
      ConfigModule.forRoot({
        isGlobal: true
        //, ignoreEnvFile: true
      }),
      TypeOrmModule.forRootAsync({
        imports: [ConfigModule],
        useFactory: (configService: ConfigService) =&gt; ({
          type: 'mysql',
          host: configService.get('DB_HOST'),
          port: configService.get&lt;number&gt;('DB_PORT'),
          username: configService.get('DB_USERNAME'),
          password: configService.get('DB_PASSWORD'),
          database: configService.get('DB_DATABASE'),
          synchronize: true,
          autoLoadEntities: true,
        }),
        inject: [ConfigService],
      })
      , UserModule, AuthModule, FormModule, InventoryModule,
    ],
    controllers: [AppController],
  })
  export class AppModule {
    constructor(private connection: Connection) { }
  }</code></pre>
  </div>
  </div>
  </p>
  <p>if I add imports ConfigModule and inject ConfigService, it gives exact error at nest start. I just can't identify where the problem is.
  AuthModule.ts:
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import { Module } from '@nestjs/common';
  import { AuthController } from './auth.controller';
  import { LdapStrategy } from './ldap/ldap.strategy';
  import { AuthService } from './auth.service';
  import { JwtModule } from '@nestjs/jwt';
  import { PassportModule } from '@nestjs/passport';
  import { jwtConstants } from './jwt/constants';
  import { JwtStrategy } from './jwt/jwt.strategy';
  import { UserModule } from 'src/user/user.module';
  import { JwtRefreshTokenStrategy } from './jwt/jwt.refresh.strategy';
  import { ConfigModule, ConfigService } from '@nestjs/config';
  
  @Module({
      imports: [
          PassportModule,
          //ConfigModule,
          JwtModule.registerAsync({
              //imports: [ConfigModule],
              useFactory: async (configService: ConfigService) =&gt; ({
                  secret: configService.get&lt;string&gt;('JWT_SECRET'),
                  // signOptions: {
                  //  algorithm: 'HS256',
                  //  expiresIn: configService.get&lt;number&gt;('JWT_EXPIRES_IN_SEC'),
                  // }
  
              }),
              //inject: [ConfigService],
          }),
          , UserModule
      ],
      controllers: [AuthController],
      providers: [
          LdapStrategy
          , AuthService
          , JwtStrategy
          , JwtRefreshTokenStrategy
      ],
      //exports: [AuthService],
  })
  export class AuthModule { }</code></pre>
  </div>
  </div>
  </p>