Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nestjs version 8 is not supported #516

Open
1 of 4 tasks
SeyranPH opened this issue Jan 24, 2022 · 1 comment
Open
1 of 4 tasks

Nestjs version 8 is not supported #516

SeyranPH opened this issue Jan 24, 2022 · 1 comment

Comments

@SeyranPH
Copy link

SeyranPH commented Jan 24, 2022

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)

@ludovit-ubrezi
Copy link

Change @Inject('ConfigService') to @Inject(ConfigService) without '

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants