Closed dyaacov closed 6 years ago
The AuthModule export the AuthService ?
No, should he? can you explain why
when I export it I get different error:
`
(node:32503) UnhandledPromiseRejectionWarning: Error: Nest cannot find given element (it does not exist in current context)
at NestApplicationContext.findInstanceByPrototypeOrToken (/Users/dekely/dev/NestJS-Starter/node_modules/@nestjs/core/nest-application-context.js:70:19)
at NestApplicationContext.find (/Users/dekely/dev/NestJS-Starter/node_modules/@nestjs/core/nest-application-context.js:38:21)
at NestApplicationContext.get (/Users/dekely/dev/NestJS-Starter/node_modules/@nestjs/core/nest-application-context.js:32:25)
at eval (webpack:///./src/server.ts?:19:70)
at Generator.next (
`
@dyaacov show your repo
can you explain why
of course, because if you would like to use a service outside from a module, you just have to export it, just it. Treat module it like a black box, if you don't make any whole for in, you won't be able to take anything from inside. This is what exports are for.
resolved!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Hi All, I'm using a global AuthGuard, I need to inject my auth-service to the AuthGuard constructor
`@Module({ imports: [AuthModule, UsersModule], providers: [ { provide: APP_GUARD, useClass: AuthGuard, }, ], })
@Injectable() export class AuthGuard implements CanActivate { constructor(private readonly authService: AuthService) { }
I get
Error: Nest can't resolve dependencies of the APP_GUARD (?). Please verify whether [0] argument is available in the current context. at Injector.lookupComponentInExports (/Users/dekely/dev/NestJS-Starter/node_modules/@nestjs/core/injector/injector.js:129:19) at process._tickCallback (internal/process/next_tick.js:68:7) at Function.Module.runMain (internal/modules/cjs/loader.js:746:11) at startup (internal/bootstrap/node.js:238:19)
`