0
votes

Err: Nest can't resolve dependencies of the TrackerService (?). Please make sure that the argument DriverModel at index [0] is available in the AppModule context. enter image description here Potential solutions:

  • If DriverModel is a provider, is it part of the current AppModule?
  • If DriverModel is exported from a separate @Module, is that module imported within AppModule? @Module({ imports: [ /* the Module containing DriverModel */ ]
app.module

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AppGateway } from './app.gateway';
import { TrackerModule } from './tracker/tracker.module';
import { MongooseModule } from '@nestjs/mongoose';

@Module({
  imports: [TrackerModule,MongooseModule.forRoot('mongodb://127.0.0.1:27017/tracker')],
  controllers: [AppController],
  providers: [AppGateway,AppService],
})
export class AppModule {}
'

tracker.module

import { Module } from '@nestjs/common';
import { TrackerService } from './tracker.service';
import { MongooseModule } from '@nestjs/mongoose';
import { DriverSchema } from './schemas/driver.schema';

@Module({
  imports: [MongooseModule.forFeature([{ name :'Driver', schema: DriverSchema }])],
  controllers: [],
  providers: [TrackerService]
})
export class TrackerModule {}


tracker.service

import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Driver } from './interfaces/driver.interface';
import { Model } from 'mongoose';
import { driverDto } from './dtos/driver.dto';

@Injectable()
export class TrackerService {
    
    constructor(@InjectModel('Driver') private driverModel: Model<Driver>){}

    addDriver( driverDTO: driverDto): Promise<Driver>{
    const newDriver = new this.driverModel(driverDTO);
    return newDriver.save();
    }
}
1
Can you be a bit specific on where do you need help here?kabirbaidhya
i can't figure out where my problem is, I've registered all my providers in their corresponding modules and imported the modules in app.module. but when i run the app i end up in that error.SHARUN VEE YES

1 Answers

0
votes

You probably have TrackerService added to the providers array of AppModule. Seeing as this provider is already in the providers array of TrackerModule you don't need to add it anywhere else. If you would like to use it elsewhere, it should be added to the exports of TrackerModule and then TrackerModule should be added to the imports of the array you want to use TrackerService in.