'"Cannot find module" with NestJS
So, I have my RootModule, a ProductModule and a StoreModule.
My RootModule:
@Module({
imports: [
ProductModule,
StoreModule,
],
controllers: [],
providers: [],
})
export class RootModule {}
My ProductModule:
@Module({
providers: [ProductService],
exports: [],
})
export class ProductModule {}
My StoreModule:
@Module({
imports: []
providers: [StoreService, StoreWaitingService],
})
export class ProductModule {}
Since my
RootModuleimports ProductModule, shouldn't I be able to useProductServiceonStoreServiceandStoreWaitingService?What if I imported ProductModule on
StoreModuleimports?
Solution 1:[1]
You can use Product Module and Service in StoreService
Product Module
@Module({
providers: [ProductService],
exports: [ProductService],
})
export class ProductModule {}
Store Module
@Module({
imports: [ProductModule],
})
export class StoreModule{}
Store service
import ProductService from '<Product Service Path>';
...
constructor(private readonly productService: ProductService){}
...
//in Function
this.productService.someFunction();
But if you don't want to import the product module in Store Module, you can make the Product Module a global Module - https://docs.nestjs.com/modules#global-modules
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nicholi Jin |
