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

相关推荐
雨奔2 小时前
Kubernetes DNS 完全指南:服务发现核心机制与实践
java·kubernetes·服务发现
是烟花哈2 小时前
【前端】React框架学习
前端·学习·react.js
逻辑驱动的ken3 小时前
Java高频面试考点场景题14
java·开发语言·深度学习·面试·职场和发展·求职招聘·春招
阿冰冰呀3 小时前
互联网大厂Java求职面试实录:谢飞机的“水货”之路
java·mybatis·dubbo·springboot·线程池·多线程·hashmap
水无痕simon3 小时前
1.单机部署Nacos1.3.2
java
qq4356947013 小时前
JavaWeb08
前端
2401_878454534 小时前
html和css的复习(1)
前端·css·html
@PHARAOH4 小时前
WHAT - git worktree 概念
前端·git
Java小生不才5 小时前
spring AI文生图
java·人工智能·spring ai
苍煜5 小时前
ThreadPoolExecutor线程池终极全解:同步异步判定+SpringBoot生产实战
java·开发语言·spring boot