在下一个主要版本中,Nest 将不允许使用 @Injectable()、@Catch() 和 @Controller() 装饰器注释的类

问题描述 投票:0回答:2

我在 Nest.js 框架中编写了 3 年,我通过后端应用程序收到了消息:

WARN [DependenciesScanner] In the next major version, Nest will not allow classes annotated with @Injectable(), @Catch(), and @Controller() decorators to appear in the "imports" array of a module.
Please remove "ExternalOrAdmin" (including forwarded occurrences, if any) from all of the "imports" arrays.

Scope [BackendAdminModule -> LicenseModule -> AuthModule]

我研究了 Nest.js github,并发现问题是什么以及为什么它说一些可用的装饰器已被弃用。

有谁知道如何解决这个问题或者 Nest.js 框架的下一个主要版本将会有什么

提前致谢!

javascript typescript dependency-injection nestjs
2个回答
15
投票

仅模块应列在

imports
数组中。这就是为什么 v9 中不再允许这种错误的用法。

阅读模块文档:https://docs.nestjs.com/modules


0
投票

您可以在

ONLY imports module(s)
数组中
imports
,此处不允许任何服务或控制器。

一般指南如下:

  • 模块->在
    imports
    数组中列出/导入。
  • 控制器-> 在
    controllers
    数组中列出/导入。
  • 服务->在
    providers
    数组中列出/注册。
  • 服务/存储库/可注入类->在
    exports
    数组中列出/注册。
© www.soinside.com 2019 - 2024. All rights reserved.