toondaey / nestjs-pdf

Nest js pdf generator
MIT License
83 stars 37 forks source link

Please make sure that the argument PdfToken(default) at index [5] is available in the AppModule context... #4

Closed ecorona closed 4 years ago

ecorona commented 4 years ago

Hi there! im trying to implement your library by following your instructions but i'm getting this error:

[Nest] 21182   - 06/19/2020, 11:24:57 PM   [ExceptionHandler] Nest can't resolve dependencies of the AppService (ProfilesService, UsersService, MyLogger, RulesService, ConfigService, ?). Please make sure that the argument PdfToken(default) at index [5] is available in the AppModule context.

Potential solutions:
- If PdfToken(default) is a provider, is it part of the current AppModule?
- If PdfToken(default) is exported from a separate @Module, is that module imported within AppModule?
  @Module({
    imports: [ /* the Module containing PdfToken(default) */ ]
  })

Is there anything missing on the exports/imports side?

thank you

ecorona commented 4 years ago

Update:

this only happens when using:

    PDFModule.registerAsync({
      useFactory: (): PDFModuleOptions => ({
        view: {
          root: './templates',
          engine: 'ejs',
        },
      }),
    }),

It works fine when using:

    PDFModule.register({
      view: {
        root: './templates',
        engine: 'ejs',
      },
    }),
toondaey commented 4 years ago

Hi @ecorona, apologies for the late response. This bug has been fixed by #5 . Please update to version 1.0.4 of the package.

hdiaz-nectia commented 3 years ago

Hi, I am using the latest version "^1.0.4", and I'm getting the same error describe above:

NestWinston] Error     2020-11-12 12:28:34 [ExceptionHandler] Nest can't resolve dependencies of the PdfService (?). Please make sure that the argument PdfToken(a) at index [0] is available in the MyAppModule context.

Potential solutions:
- If PdfToken(a) is a provider, is it part of the current MyAppModule?
- If PdfToken(a) is exported from a separate @Module, is that module imported within MyAppModule?
  @Module({
    imports: [ /* the Module containing PdfToken(a) */ ]
  })

This happens with PDFModule.register and PDFModule.registerAsync

hdiaz-nectia commented 3 years ago

I set up in my AppModule (main module)

AppModule

...
    PDFModule.register({
      view: {
        root: '/commons/template',
        engine: 'pug',
      },
    }),
...
export class AppModule {

  static port: number | string;

  constructor(private readonly _configService: AppConfigService) {
    AppModule.port = _configService.get(Configuration.PORT);
  }
}

Then I use in my child module:

LiquidacionesModule

@Module({
    imports: [
        MongooseModule.forFeature([
            { name: Liquidacion.name, schema: LiquidacionSchema },
            { name: Hes.name, schema: HesSchema },
        ])
    ],
    controllers: [LiquidacionesController],
    providers: [LiquidacionesService, HesService, ReportService, PdfService, Logger],
    exports: [LiquidacionesService]
})
export class LiquidacionesModule {}
hdiaz-nectia commented 3 years ago

When I move config from AppModule to LiquidacionesModule and it works, but I'd like it to be available for all modules, is it possible?

toondaey commented 3 years ago

I think you just have to make your config module global to get it to work that way. See here