当前位置: 首页 > article >正文

nestjs目录命名导致的循环引用

具体报错如下:

[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全是空方法仍然会出现循环引用的报错

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就正常了


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


http://www.kler.cn/a/288111.html

相关文章:

  • 基于OpenCV的图片人脸检测研究
  • 字节青训营 数字魔法的加一操作
  • vue3:computed
  • Cellebrite VS IOS18Rebooting
  • C#语言详解:从基础到进阶
  • 【OpenEuler】配置虚拟ip
  • Spring Cloud全解析:负载均衡之Ribbon的负载均衡算法
  • C++:类和对象(二)
  • C++:构造函数与析构函数
  • MySQL数据库(0)—— 云服务器安装MySQL
  • 【Godot4.3】基于纯绘图函数自定义的线框图控件
  • 1、Django Admin学习模型
  • SpringBoot配置Java后端服务器
  • Nuclei文件上传小Tips
  • 多目标应用:基于环形拓扑的多目标粒子群优化算法(MO_Ring_PSO_SCD)的移动机器人路径规划研究(提供MATLAB代码)
  • 不用async与await将异步函数改为同步函数
  • MySQL 数据库课程设计
  • 软件测试学习笔记丨Chrome开发者模式
  • Linux-vim
  • 从自动驾驶看无人驾驶叉车的技术落地和应用
  • HTTP 之 HTTP头部优化策略(九)
  • Spring Boot 整合 Sentinel 实现流量控制
  • Facebook的AI革新:如何利用人工智能提升你的社交体验
  • Golang 教程5——函数02(时间函数、内建函数、错误机制)
  • 海外云手机实现海外社媒矩阵营销
  • 计算机网络(八股文)