Hi All,
I have the following structure:
NotificationsController
|--- EmailService
|------- EmailClient
EmailService is injected fine into the controller EmailClient is not injected into EmailService.
is there a limitation?
`
@Controller('api/v1/notifications')
export class NotificationsController {
constructor(private readonly emailService: EmailService) { }
@Injectable()
export class EmailService {
constructor(private readonly client: EmailClient) { }
@Injectable()
export class EmailClient {
async send(data) {
}
}
`
Thanks
Dekel
Hey, could tou show us your module implementation as well
`
import { Module } from '@nestjs/common'
import { NotificationsController, SMSService, EmailService, EmailClient, SMSClient } from '../'
@Module({
imports: [],
controllers: [NotificationsController],
providers: [SMSService, EmailService, EmailClient, SMSClient],
})
export class NotificationsModule { }
`
And what is the error that you’v got ?
in EmailService constructor, the client is null
@Injectable()
export class EmailService {
constructor(private readonly client: EmailClient) { }
But what error do you have ?
I don't see any error, that's the problem...
22:15 $ npm run start:dev
[email protected] start:dev /Users/dekely/dev/NestJS-Starter
nodemon
[nodemon] 1.17.5
[nodemon] reading config ./nodemon.json
[nodemon] to restart at any time, enter rs
[nodemon] or send SIGHUP to 37005 to restart
[nodemon] ignoring: /.test.ts */.spec.ts ./.git// ./node_modules//*
[nodemon] watching: /Users/dekely/dev/NestJS-Starter/src//*
[nodemon] watching extensions: ts
[nodemon] starting node --inspect -r ts-node/register ./src/server.ts
[nodemon] spawning
[nodemon] child pid: 37007
Debugger listening on ws://127.0.0.1:9229/aa07e011-ea51-42ec-861f-c94bacc2d860
For help see https://nodejs.org/en/docs/inspector
[nodemon] watching 20 files
[Nest] 37007 - 2018-7-9 22:15:51 [NestFactory] Starting Nest application...
[Nest] 37007 - 2018-7-9 22:15:51 [InstanceLoader] ApplicationModule dependencies initialized +20ms
[Nest] 37007 - 2018-7-9 22:15:51 [InstanceLoader] NotificationsModule dependencies initialized +0ms
[Nest] 37007 - 2018-7-9 22:15:51 [RoutesResolver] NotificationsController {/api/v1/notifications}: +34ms
[Nest] 37007 - 2018-7-9 22:15:51 [RouterExplorer] Mapped {/email, POST} route +3ms
[Nest] 37007 - 2018-7-9 22:15:51 [RouterExplorer] Mapped {/sms, POST} route +2ms
[Nest] 37007 - 2018-7-9 22:15:51 [NestApplication] Nest application successfully started +1ms
In your bootstrap could tou try to get the service and print the result ?
‘Console.log(app.get(EmailClient))’
console.log('EmailClient:', app.get(EmailClient))
result:
EmailClient: EmailClient {}
And what error do you get if you call the send method ?
TypeError: Cannot read property 'send' of undefined
because this. client is undefined
It is weird, everything seams to be done in a good way, what looks like your AppModule
I eliminated everything but the NotificationsModule
`
import { Module } from '@nestjs/common';
import { NotificationsModule } from '../notifications/modules/notifications.module';
@Module({
imports: [NotificationsModule],
})
export class ApplicationModule { }
`
any chance its a configuration issue? tsconfig.json?
I tried something similar locally, i dont have any problem.
Could you share a repo please, with the exact config and implementation
In your config, you have to enable "emitDecoratorMetadata": true
Then try this in your bootstrap app.get(EmailService).send({ key: 'value' })
it should work
Yes!!!
I spent 2 days on this...
Thank you very much adrien
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.
Most helpful comment
Yes!!!
I spent 2 days on this...
Thank you very much adrien