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

相关推荐
金銀銅鐵5 小时前
带您看懂字节码指令(番外二):递归里有什么——三层 fact 帧怎么叠起来
java·jvm·后端
两点王爷7 小时前
Java 面试高频:JWT、Cookie、Session、Token 鉴权详解
java·开发语言·面试
Java展博8 小时前
[前端够用就好] 跨域报错时,浏览器到底在拦谁
前端·状态模式
用户112936112199 小时前
npm 都提示成功了,node_modules 为什么还占着 370M?
linux·前端·后端
悟道书生9 小时前
hashMap/hashSet/hashCode详解
java
掘金安东尼10 小时前
Agent Harness 也有 benchmark:评分榜与评测工作台现状
前端·agent
digger_41910 小时前
从零理解 Electron:主进程、渲染进程、preload 与 IPC 实战
前端·electron
nice_lcj52010 小时前
依赖注入的三种方式:构造器、Setter、字段怎么选
java·spring·面试·依赖注入·字段注入·构造器注入
噢,我明白了10 小时前
实际项目导出方式应用
java·状态模式·导出