簡體   English   中英

NestJS - Nest 無法解析 ConfigurationService 的依賴項(ConfigService,?)

[英]NestJS - Nest can't resolve dependencies of the ConfigurationService (ConfigService, ?)

我是 NestJs + Typescript 的新手,試圖初始化一個項目,在構建它之后會引發以下錯誤:

ERROR [ExceptionHandler] Nest can't resolve dependencies of the ConfigurationService (ConfigService, ?). Please make sure that the argument CachingService at index [1] is available in the ConfigurationService context.

我嘗試了很多可能的方法來解決這個問題,但還沒有運氣

這些是有問題的兩個模塊:

import { CacheModule, Module } from '@nestjs/common';
import { CachingService } from './caching.service';

@Module({
  imports: [
    CacheModule.register({
      ttl: 0,
    }),
  ],
  providers: [CachingService],
  exports: [CachingService],
})
export class CachingModule {}
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { CachingModule } from '../caching/caching.module';
import { ConfigurationService } from './configuration.service';

import { config } from './environmentConfig/default.config';
import deploymentConfig from './deploymentConfig/config';
import { CachingService } from '../caching/caching.service';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      load: [() => config, deploymentConfig],
    }),
    CachingModule,
  ],
  providers: [ConfigurationService, CachingService],
  exports: [ConfigurationService],
})
export class ConfigurationModule {}

這是我嘗試使用緩存模塊的服務並且正在引發錯誤:

import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

import { CachingService } from '../caching/caching.service';

@Injectable()
export class ConfigurationService implements OnModuleInit {
  private readonly logger = new Logger(ConfigurationService.name);

  constructor(
    private readonly configService: ConfigService,
    private cachingService: CachingService,
  ) {}

如何解決這個問題?

在 ConfigurationModule 中刪除 CachingService 作為提供程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM