nestjs-sentry
nestjs-sentry copied to clipboard
Nest can't resolve dependencies of the GraphqlInterceptor (?)
Are there better instructions on how I should be loading in other dependencies for the providers
sample code in the README.md to work?
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 */ ]
})
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
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 thanks. I'll use this as a work around for the time being.
some problem how to fixed ?
some problem how to fixed ?
use the useFactory instead of useClass as described above by kachar
Thanks.. I'll update the documentation @uptownhr @productfrontenddeveloper @kachar
One workaround is to use
useValue: new SentryInterceptor()
instead ofuseClass: SentryInterceptor
but that's not very efficient
I think if we just use useValue nestjs will handle instantiation
providers: [
{
provide: APP_INTERCEPTOR,
useValue: SentryInterceptor,
},
],
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 Thanks for checking this.
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.