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 分钟前
基于微信小程序的健身房管理系统
java·tomcat·maven
new code Boy3 分钟前
前端base-64 编码解码
前端·javascript·html
大志哥1236 分钟前
IntelliJ IDEA父子工程中导入公网远程备份项目到新目录
java·ide·intellij-idea
廋到被风吹走7 分钟前
【Spring】DefaultListableBeanFactory 详解
java·python·spring
东东的脑洞8 分钟前
【面试突击八】Spring IOC:Bean 创建流程全解析(从 getBean 到 AOP 代理生成)
java·spring·面试
灰色人生qwer9 分钟前
VS Code 配置Java环境
java·开发语言
前端摸鱼匠10 分钟前
Vue 3 的watch监听多个数据源:讲解如何同时监听多个响应式数据的变化
前端·javascript·vue.js·前端框架·ecmascript
tgethe10 分钟前
Java 链表(LinkedList)
java·开发语言·链表
梁萌12 分钟前
idea使用AI插件(CodeGeeX)
java·ide·ai·intellij-idea·插件·codegeex
文心快码BaiduComate13 分钟前
用Spec给AI Agent立规矩,AI编码告别手忙脚乱
前端·后端·前端框架