【问题标题】:nest js : Error: Nest can't resolve dependencies of the PlanningService (?)nest js:错误:Nest 无法解析 PlanningService 的依赖项(?)
【发布时间】:2021-06-04 06:24:12
【问题描述】:

我在 app.module 中导入planning.module 时遇到了这个错误:

Nest 无法解析 PlanningService (?) 的依赖关系。请确保参数 PlanningMo 索引 [0] 处的 del 在 PlanningModule 上下文中可用。

可能的解决方案: - 如果 PlanningModel 是提供者,它是当前 PlanningModule 的一部分吗? - 如果 PlanningModel 是从一个单独的 @Module 导出的,那么该模块是在 PlanningModule 中导入的吗? @模块({ 导入:[ /* 包含 PlanningModel 的模块 */ ] })

这是我的planning.module

import { Module } from '@nestjs/common';
import { PlanningController } from './planning.controller';
import { PlanningService } from './planning.service';
import {MongooseModule} from "@nestjs/mongoose";
import {PlanningSchema} from "./schemas/planning.schema";
import {UserModule} from "../user/user.module";



@Module({
  imports: [MongooseModule.forFeature([{ name: 'Planing', schema: PlanningSchema }]),UserModule],
  providers: [PlanningService],
  exports: [PlanningService],
  controllers: [PlanningController]

})


export class PlanningModule {}

app.module.ts

import {Module, NestModule, MiddlewareConsumer, RequestMethod} from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { MongooseModule } from '@nestjs/mongoose';
import { mongoConfig } from './config';
import { UserModule } from './user/user.module';
import { AuthModule } from './auth/auth.module';
import { JwtMidelware } from './utils/jwtMidelware';
import {UserController} from "./user/user.controller";

import { TeamModule } from './team/team.module';

import { CompanyModule } from './company/company.module';

import { AgenceModule } from './agence/agence.module';
import { PlanningModule } from './planning/planning.module';


@Module({
  imports: [
    MongooseModule.forRoot(mongoConfig.url, mongoConfig.auth),
    PlanningModule,
    UserModule,
    AuthModule,
    TeamModule,
    CompanyModule,
    AgenceModule,
  ]



})
export class AppModule implements NestModule {

  configure(consumer: MiddlewareConsumer) {
    consumer
        .apply(JwtMidelware)
        .exclude(
            { path: 'users/id', method: RequestMethod.GET },
        )
        .forRoutes(UserController);
  }

}

【问题讨论】:

  • 你能把构造函数展示给PlaningService吗?
  • @JayMcDoniel 构造函数(@InjectModel('Planning') 私有只读 PlanningModel: PaginateModel, ) { }

标签: nestjs


【解决方案1】:

在您的构造函数中有@InjectModel('Planning'),但在您的MongooseModule.forFeature() 中有{ name:'Planing',...}。这些字符串需要匹配。

【讨论】:

  • 哦..是的,就是这样,我错过了...感谢您的帮助
猜你喜欢
  • 2023-02-04
  • 2021-10-17
  • 2023-01-31
  • 2022-11-12
  • 2023-04-01
  • 2020-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多