After following the Nest JS Crash tutorial from a Youtube Link, I encountered an error when importing an interface in the service.
Nest seems unable to resolve dependencies of the ItemsService. It's important to ensure that the argument at index [0] is available in the AppModule context.
Although the cloned repository provided in the tutorial works perfectly, copying the src folder to my own project leads to errors. Here's a snippet of my Service file:
import { Injectable } from '@nestjs/common';
import { Item } from './interfaces/item.interface';
import { Model } from 'mongoose';
import { ItemsModule } from './items.module'
import { InjectModel } from '@nestjs/mongoose';
@Injectable()
export class ItemsService {
constructor(@InjectModel('Item') private readonly itemModel: Model<Item>) {}
});
}
Interestingly, commenting out the constructor line resolves the issue. The problem might stem from this particular import statement:
import { Model } from 'mongoose';
Hovering over this line indicates that there could not find a declaration for this module. Even copying the package.json file from the working code didn't change the error message.
The Items module includes various files such as controller, service, module, dto, interface, and schema.