【问题标题】:Nest can't resolve dependencies of the I18nLanguageInterceptorNest 无法解析 I18nLanguageInterceptor 的依赖关系
【发布时间】:2022-01-17 22:16:27
【问题描述】:

将nest 升级到v8 后,我无法使nestjs-i18n 正常工作。

这是我遇到的错误

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 */ ]  })  

版本:

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

感谢您的帮助

【问题讨论】:

  • 你在使用 monorepo 吗?

标签: nestjs nestjs-i18n


【解决方案1】:

您的模块 I18nLanguageInterceptor 必须解析构造函数中的所有依赖项。 在这种情况下,您遇到了最后一个问题(I18nOptions、I18nResolvers、I18nService、?)。

你在哪里注入 I18nLanguageInterceptor 模块?,你能告诉我你的 app.module 还是你用这个 I18nLanguageInterceptor 模块构建的任何东西。

来帮忙!

【讨论】:

  • I18nLanguageInterceptor interceptor 不在 OP 的代码中,它是从 nestjs-i18n 加载的,没关系。这里的问题是如何导入依赖项。可能@nestjs/core 被导入了两次,来自两个不同的nodejs 模块。
【解决方案2】:

基本上,当您有多个 ModuleRef 类对象的值时,会发生这种情况,这会使 Nest 查找错误的值,这使得 x instanceOf ModuleRef(内部完成)返回 false

这可能是因为您的项目中有两个@nestjs/core nodejs 模块。

你可以通过这样做找到这个

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)

(假设是一个非 monorepo 项目)

【讨论】:

    猜你喜欢
    • 2018-11-21
    • 2020-03-12
    • 2020-07-03
    • 2021-04-28
    • 2020-03-07
    • 2019-12-15
    • 2020-12-14
    • 2020-12-13
    • 2019-12-09
    相关资源
    最近更新 更多