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在进行目录解析的时候进行了一些独特的处理 导致有的命名无法正常解析

相关推荐
Yoyo25年秋招冲冲冲10 分钟前
Day63_20250211_图论part7 prim算法|kruskal算法精讲
java·数据结构·算法·深度优先·图论
IT专家-大狗12 分钟前
如何在Java中使用JUnit进行单元测试
java·junit·单元测试
小小AK37 分钟前
数据集成实例分享:金蝶云星空对接旺店通实现库存管理自动化
java·运维·自动化
娶个名字趴44 分钟前
网络编程(TCP/UDP)
java·服务器·网络·网络协议·tcp/ip·udp·java-ee
患得患失9491 小时前
【前端】【面试】ref与reactive的区别
前端·面试·vue3
橘猫云计算机设计1 小时前
基于JavaWeb的在线美食分享平台(源码+lw+部署文档+讲解),源码可白嫖!
java·hadoop·spring boot·信息可视化·django·美食
nqqcat~1 小时前
集合7天学java—day2
java·开发语言
if就1 小时前
Java_多线程
android·java·开发语言
后端小肥肠1 小时前
FastExcel + Java:打造高效灵活的Excel数据导入导出解决方案
java·开发语言·spring boot·后端·excel
是小崔啊2 小时前
Mybatis源码02 - 初始化基本过程(引导层部分)
java·mybatis·原理