nestjs-sentry icon indicating copy to clipboard operation
nestjs-sentry copied to clipboard

Nest can't resolve dependencies of the GraphqlInterceptor (?)

Open uptownhr opened this issue 3 years ago • 10 comments

Are there better instructions on how I should be loading in other dependencies for the providers sample code in the README.md to work?

image

Adding in the providers with APP_INTERCEPTOR for GraphqlInterceptor results in

ERROR [ExceptionHandler] Nest can't resolve dependencies of the GraphqlInterceptor (?). Please make sure that the argument Object at index [0] is available in the AppModule context.

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

uptownhr avatar Sep 20 '21 20:09 uptownhr

I've ended up in the same scenario when trying to import SentryInterceptor

[Nest] 638883  - 09/21/2021, 11:45:51 AM     LOG [InstanceLoader] SentryModule dependencies initialized +143ms
[Nest] 638883  - 09/21/2021, 11:45:51 AM   ERROR [ExceptionHandler] Nest can't resolve dependencies of the SentryInterceptor (?). Please make sure that the argument Object at index [0] is available in the AppModule context.

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

Error: Nest can't resolve dependencies of the SentryInterceptor (?). Please make sure that the argument Object at index [0] is available in the AppModule context.

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

A possible solution might be to add exports: [SentryInterceptor, GraphqlInterceptor] in sentry.module.ts

If that's a good way forward I'm up for creating a PR

kachar avatar Sep 21 '21 08:09 kachar

One workaround is to use useValue: new SentryInterceptor() instead of useClass: SentryInterceptor but that's not very efficient

    {
      provide: APP_INTERCEPTOR,
-      useClass: SentryInterceptor,
+      useValue: new SentryInterceptor(),
    },

Better alternative might be to useFactory

    {
      provide: APP_INTERCEPTOR,
-      useClass: SentryInterceptor,
+      useFactory: () => new SentryInterceptor(),
    },

kachar avatar Sep 21 '21 09:09 kachar

@kachar thanks. I'll use this as a work around for the time being.

uptownhr avatar Sep 21 '21 16:09 uptownhr

some problem how to fixed ?

productdevbook avatar Sep 22 '21 07:09 productdevbook

some problem how to fixed ?

use the useFactory instead of useClass as described above by kachar

uptownhr avatar Sep 22 '21 12:09 uptownhr

Thanks.. I'll update the documentation @uptownhr @productfrontenddeveloper @kachar

ntegral avatar Oct 11 '21 16:10 ntegral

One workaround is to use useValue: new SentryInterceptor() instead of useClass: SentryInterceptor but that's not very efficient

I think if we just use useValue nestjs will handle instantiation

providers: [
    {
      provide: APP_INTERCEPTOR,
      useValue: SentryInterceptor,
    },
  ],

boy51 avatar Oct 15 '21 10:10 boy51

Hi all,

@ntegral I tested both useValue and useFactory. Seems that interceptor is not instanciated with useValue, working as expected with useFactory [Nestjs 7, lib 2.x.x].

MichFe avatar Oct 28 '21 01:10 MichFe

@MichFe Thanks for checking this.

ntegral avatar Dec 02 '21 14:12 ntegral

I'm seeing this with @nestjs/core v8.4.7 and @ntegral/nestjs-sentry v3.0.7 just by introducing the upgraded @ntegral/nestjs-sentry package into my repo.

chiubaka avatar Jun 30 '22 19:06 chiubaka