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

相关推荐
彭于晏Yan5 分钟前
Spring AI(二):入门使用
java·spring boot·spring·ai
楠木68511 分钟前
RAG 资料库 Demo 完整开发流程
前端·ai编程
有一个好名字19 分钟前
vibe codeing 开发流程
java
肠胃炎22 分钟前
挂载方式部署项目
服务器·前端·nginx
兑生25 分钟前
【灵神题单·贪心】3745. 三元素表达式的最大值 | 排序贪心 | Java
java·开发语言
polaris063030 分钟前
Windows操作系统部署Tomcat详细讲解
java·windows·tomcat
像我这样帅的人丶你还30 分钟前
使用 Next.js + Prisma + MySQL 开发全栈项目
前端
FPGA小迷弟31 分钟前
FPGA 时序约束基础:从时钟定义到输入输出延迟的完整设置
前端·学习·fpga开发·verilog·fpga
Kel31 分钟前
深入剖析 openai-node 源码:一个工业级 TypeScript SDK 的架构之美
javascript·人工智能·架构
卓怡学长1 小时前
m280本科生导师指导平台
java·数据库·spring·tomcat·maven·intellij-idea