Skip to content

Nestjs version 8 is not supported #516

@SeyranPH

Description

@SeyranPH

Issue type:

  • question
  • bug report
  • feature request
  • documentation issue

nestjs-config version
Version tag: 1.4.5

  • @nestjs/common: 8.2.6
  • @nestjs/core: 8.2.6

Excepted behavior

It seems that nestjs-common doesn't support nestjs version 8.

Actual behavior or outcome (for issue)

Importing and injecting configService from nestjs-config is not supported.

Replication/Example

crypto.service.ts file

import { Injectable, Inject } from '@nestjs/common';
import * as crypto from 'crypto';
import { ConfigService } from 'nestjs-config';

@Injectable()
export class CryptoService {
  constructor(@Inject('ConfigService') private readonly configService: ConfigService) {}

  createHash(data: string, secret: string): string {
    // creating hmac object
    const hmac = crypto.createHmac('sha256', secret);
    // passing the data to be hashed
    const hash = hmac.update(data);
    // Creating the hmac in the required format
    const resultInBase64 = hash.digest('base64');

    return resultInBase64;
  }

  createMD5Hash(data: string): string {
    const md5 = crypto.createHash('md5').update(data).digest('hex');

    return md5;
  }
}

This is working properly with nestjs version 7. However with nestjs version 8 I'm getting an error.
The error message I'm getting:

Nest can't resolve dependencies of the CryptoService (?). Please make sure that the argument ConfigService at index [0] is available in the CryptoModule context.

    Potential solutions:
    - If ConfigService is a provider, is it part of the current CryptoModule?
    - If ConfigService is exported from a separate @Module, is that module imported within CryptoModule?
      @Module({
        imports: [ /* the Module containing ConfigService */ ]
      })

      at TestingInjector.lookupComponentInParentModules (../node_modules/@nestjs/core/injector/injector.js:202:19)
      at TestingInjector.resolveComponentInstance (../node_modules/@nestjs/core/injector/injector.js:157:33)
      at TestingInjector.resolveComponentInstance (../node_modules/@nestjs/testing/testing-injector.js:16:45)
      at resolveParam (../node_modules/@nestjs/core/injector/injector.js:108:38)
          at async Promise.all (index 0)
      at TestingInjector.resolveConstructorParams (../node_modules/@nestjs/core/injector/injector.js:123:27)
      at TestingInjector.loadInstance (../node_modules/@nestjs/core/injector/injector.js:52:9)
      at TestingInjector.loadProvider (../node_modules/@nestjs/core/injector/injector.js:74:9)
          at async Promise.all (index 3)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions