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

相关推荐
盐水冰1 分钟前
【烘焙坊项目】后端搭建(6)- 店铺状态设置
java·redis
yangyanping201082 分钟前
Vue入门到精通七之关键字const
前端·javascript·vue.js
健康平安的活着3 分钟前
java中乐观锁+事务在批量导入,批量审批案例的使用
java·开发语言
夏语灬4 分钟前
SpringBoot集成MQTT客户端
java·spring boot·后端
Memory_荒年6 分钟前
Spring Boot自动装配:告别“配置地狱”的智能管家
java·后端·spring
姝然_952713 分钟前
Jetpack Compose 绘制流程与自定义布局
前端
lxh011313 分钟前
重复的DNA序列
开发语言·javascript·ecmascript
姝然_952713 分钟前
Jetpack Compose Brush 渐变
前端
盐水冰21 分钟前
【烘焙坊项目】后端搭建(9)- 缓存实现及购物车相关功能开发
java·后端·spring
gameboy03121 分钟前
在Nginx上配置并开启WebDAV服务的完整指南
java·运维·nginx