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

相关推荐
e***U82021 小时前
React Hooks性能优化
前端·react.js·前端框架
4***R24021 小时前
React数据分析
前端·react.js·前端框架
X***E46321 小时前
React课程
前端·react.js·前端框架
4***997421 小时前
React音频处理案例
前端·react.js·音视频
1***815321 小时前
React组件
前端·javascript·react.js
6***34921 小时前
Vue混合现实案例
前端·vue.js·mr
p***43481 天前
Vue混合现实开发
前端·vue.js·mr
爱笑的眼睛111 天前
PyTorch Lightning:重新定义深度学习工程实践
java·人工智能·python·ai
ArkPppp1 天前
大道至简-Shadcn/ui设计系统初体验(下):Theme与色彩系统实战
前端·前端框架
炒米23331 天前
通义千问Qwen3-Coder模型帮我总结的typescript笔记
前端