Wantedsystem
Wantedsystem

Reputation: 1

Nest can't resolve dependencies of the I18nLanguageInterceptor

After upgrading nest to v8, I'm having problem making nestjs-i18n work.

Here's the Error I'm getting

Nest can't resolve dependencies of the I18nLanguageInterceptor (I18nOptions, I18nResolvers, I18nService, ?). Please make sure that the argument ModuleRef at index [3] is available in the I18nModule context.

Potential solutions:
 If ModuleRef is a provider, is it part of the current I18nModule?
 If ModuleRef is exported from a separate @Module, is that module imported within I18nModule?
@Module({
  imports: [ /* the Module containing ModuleRef */ ]
 })
 - {"stack":["Error: Nest can't resolve dependencies of the I18nLanguageInterceptor (I18nOptions, I18nResolvers, I18nService, ?).
 
 Please make sure that the argument ModuleRef at index [3] is available in the I18nModule context.
 
 Potential solutions:
 - If ModuleRef is a provider, is it part of the current I18nModule?
 - If ModuleRef is exported from a separate @Module, is that module imported within I18nModule? 
 @Module({    imports: [ /* the Module containing ModuleRef */ ]  })  

Versions:

 "@nestjs/common": "^8.2.0",
 "@nestjs/core": "^8.2.0",
 "nestjs-i18n": "8.2.2",
 "rxjs": "^7.4.0",

Thank you for your help

Upvotes: 0

Views: 3618

Answers (3)

SMJ
SMJ

Reputation: 776

try installing jest-mock-extended package if you're getting error from testcases.

import { mockDeep } from 'jest-mock-extended';
import { I18nService } from 'nestjs-i18n';
describe('ZController', () => {
  let controller: ZController;
  const i18nServiceMock = mockDeep<I18nService>();

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      controllers: [ZController],
      providers: [
        {
          provide: I18nService,
          useValue: i18nServiceMock,
        },
        {
          provide: HttpService,
          useValue: {
            get: jest.fn().mockResolvedValue({}),
          },
        },
      ],
    }).compile();

    controller = module.get<ZController>(ZController);
  });

Upvotes: 1

Micael Levi
Micael Levi

Reputation: 6695

basically, this happens when you have several values of ModuleRef class object, making Nest looking up for the wrong one, which makes x instanceOf ModuleRef (that's done internally, roughly) returning false

This is probably because you have two @nestjs/core nodejs modules in your project.

You can find this out by doing

ls -l node_modules/nestjs-i18n/@nestjs
## will display `core` (which is not expected)

ls -l node_modules/@nestjs
## will display `core` (which is expected)

(assuming a non-monorepo project)

Upvotes: 1

Juan Botero
Juan Botero

Reputation: 1

Hi Your module I18nLanguageInterceptor has to resolve al the dependencies that have in the constructor. In this case you are having problems with the last (I18nOptions, I18nResolvers, I18nService, ?).

Where are you injecting I18nLanguageInterceptor module?, can you show me your app.module or whatever are you building with this I18nLanguageInterceptor module.

Here to help!

Upvotes: 0

Related Questions