Hi,
im using a microservices and i want to create a shared module. The module is build and deployed via an npm package and uses the ClientsModule.
If i integrate the code in one project everything is working.
my.module.ts
import { ClientsModule } from '@nestjs/microservices'
@Module({
imports: [
ClientsModule.registerAsync([
{
name: 'MY_CLIENT'
}
])
],
providers: [MyService],
exports: [MyService]
})
export class MyModule {}
my.service.ts
import { Inject, Injectable } from '@nestjs/common'
@Injectable()
export class MyService {
constructor(@Inject('MY_CLIENT') private readonly client: ClientProxy) {}
}
app.module.ts
import MyModule from './myModule.ts'
@Module({
imports: [
MyModule
]
})
export class AppModule {}
When i build the code of my.service.ts and my.module.ts in an npm package myLibary, export it via the index.ts and change the import to import MyModule from 'myLibary' i get this error
Error starting the application: UndefinedDependencyException [Error]: Nest can't resolve dependencies of the MY_CLIENT (?). Please make sure that the argument dependency at index [0] is available in the MyModule context.
Potential solutions:
- Is MyModule a valid NestJS module?
- If dependency is a provider, is it part of the current MyModule?
- If dependency is exported from a separate @Module, is that module imported within MyModule?
@Module({
imports: [ /* the Module containing dependency */ ]
})
I checked the https://docs.nestjs.com/faq/common-errors page so its maybe a circular file import?
Any ideas or solutions? Thanks for the help.