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

相关推荐
午安~婉几秒前
HTML CSS八股
前端·css·html
有事没事实验室2 分钟前
css变量
前端·css
前端付豪14 分钟前
Vue 中的 JSX:让组件渲染更灵活的正确方式
前端·javascript·vue.js
在泡泡里14 分钟前
前端规范【四】eslint(antfu)、lefthook、commitlint
前端
烛阴15 分钟前
Python 几行代码,让你的照片秒变艺术素描画
前端·python
Kuo-Teng21 分钟前
LeetCode 73: Set Matrix Zeroes
java·算法·leetcode·职场和发展
王元_SmallA24 分钟前
服务器公网IP、私网IP、弹性IP是什么?区别与应
java·后端
Jolyne_39 分钟前
如何实现无感刷新Token
前端
葵续浅笑44 分钟前
LeetCode - 杨辉三角 / 二叉树的最大深度
java·数据结构·算法·leetcode
用户4099322502121 小时前
Vue3响应式系统的底层原理与实践要点你真的懂吗?
前端·ai编程·trae