nestjs目录命名导致的循环引用

具体报错如下:

bash 复制代码
[Nest] 2024  - 2024/09/02 22:57:02   ERROR [ExceptionHandler] A circular dependency has been detected inside ApplicationModule. Please, make sure that each side of a bidirectional relationships are decorated with "forwardRef()". Note that circular relationships between custom providers (e.g., factories) are not supported since functions cannot be called more than once.
Error: A circular dependency has been detected inside ApplicationModule. Please, make sure that each side of a bidirectional relationships are decorated with "forwardRef()". Note that circular relationships between custom providers (e.g., factories) are not supported since functions cannot be called more than once.

复现方式:尽管U8AppService全是空方法仍然会出现循环引用的报错

typescript 复制代码
import { App } from "@/entities/app.entity";
import { TypeOrmModule } from "@hg/born-typeorm";
import { Module, Injectable } from "@hg/born/common";
import { ApplicationController } from "./controller";
import { U8AppService } from "./Service";

@Module({
    imports: [TypeOrmModule.forFeature([App])],
    controllers: [ApplicationController],
    providers: [U8AppService],
    exports: [U8AppService],
})
export class ApplicationModule { }

修改方法:将目录名从Service改为base就正常了

typescript 复制代码
import { App } from "@/entities/app.entity";
import { TypeOrmModule } from "@hg/born-typeorm";
import { Module, Injectable } from "@hg/born/common";
import { ApplicationController } from "./controller";
import { U8AppService } from "./base";

@Module({
    imports: [TypeOrmModule.forFeature([App])],
    controllers: [ApplicationController],
    providers: [U8AppService],
    exports: [U8AppService],
})
export class ApplicationModule { }

猜测nestjs在进行目录解析的时候进行了一些独特的处理 导致有的命名无法正常解析

相关推荐
じòぴé南冸じょうげん3 分钟前
小程序的project.private.config.json是无依赖文件,那可以删除吗?
前端·小程序·json
渣哥10 分钟前
我和Java 8 Stream相爱相杀的那些年
java
爱吃烤鸡翅的酸菜鱼11 分钟前
【Spring】原理解析:Spring Boot 自动配置
java·spring boot
小白兔35312 分钟前
一文讲通Unicode规范、UTF-8与UTF-16编码及在Java中的验证
java
会豪13 分钟前
Electron主进程渲染进程如何优雅的进行通信
前端
jianghaha201113 分钟前
前端 Word 模板参入特定数据 并且下载
前端·word
跟橙姐学代码13 分钟前
轻松搞定 Python 模块与包导入:新手也能秒懂的入门指南
前端·python·ipython
十八旬18 分钟前
苍穹外卖项目实战(day7-1)-缓存菜品和缓存套餐功能-记录实战教程、问题的解决方法以及完整代码
java·数据库·spring boot·redis·缓存·spring cache
aiwery19 分钟前
大模型场景下的推送技术选型:轮询 vs WebSocket vs SSE
前端·agent
会豪20 分钟前
前端插件-不固定高度的DIV如何增加transition
前端