简体   繁体   中英

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

I am new to NestJs + Typescript, trying to initialize a project, after building it throws the following error:

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.

I tried many possible ways to solve this but no luck yet

These are the two modules in question:

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 {}

This is the service where I am trying to use the cachingModule and the error is being thrown:

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,
  ) {}

How to fix this?

在 ConfigurationModule 中删除 CachingService 作为提供程序。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM