首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nest不能创建AuthModule实例

Nest不能创建AuthModule实例
EN

Stack Overflow用户
提问于 2021-12-06 18:22:44
回答 1查看 1K关注 0票数 -1

当试图在用户模型和组之间建立链接时,会发生以下错误:

我不明白为什么..。

代码语言:javascript
复制
[Nest] 30312  - 06.12.2021, 20:53:42     LOG [NestFactory] Starting Nest application...
[Nest] 30312  - 06.12.2021, 20:53:42   ERROR [ExceptionHandler] Nest cannot create the AuthModule instance.
The module at index [1] of the AuthModule "imports" array is undefined.

Potential causes:
- A circular dependency between modules. Use forwardRef() to avoid it. Read more: https://docs.nestjs.com/fundamentals/circular-dependency
- The module at index [1] is of type "undefined". Check your import statements and the type of the module.

Scope [AppModule]
Error: Nest cannot create the AuthModule instance.
The module at index [1] of the AuthModule "imports" array is undefined.

app.module.ts https://pastebin.com/T9EC05gS

users.module.ts https://pastebin.com/inS044Xk

user.model.ts https://pastebin.com/wpyUs2SW

groups.module.ts https://pastebin.com/Jvr2Fuk3

group.model.ts https://pastebin.com/nBvkaEUt

auth.module.ts https://pastebin.com/MYQ2dw6y

auth.guard.ts https://pastebin.com/xDpQ8vwE

auth.service.ts https://pastebin.com/G9TzN3XF

提前感谢

UPD:在添加

代码语言:javascript
复制
  @Expose()
  @HasMany(() => Group)
  groups: Group[];

转到user.model.ts

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-06 20:02:35

在您的auth.module.ts文件中,而不是

import { UsersModule } from '../users';尝试

import { UsersModule } from '../users/user.module';

我相信这些桶文件(index.ts导出所有东西)在这里不是一个好的模式,因为它在NestJS模块之间引入了循环导入。

1 auth.module.ts imports users/index.ts (我猜它导出user.module.ts )

2 groups.module.ts imports auth/index.ts (我猜它导出auth.module.ts )

3 user.model.ts进口groups/index.ts

然后你就会得到一个导入3和3个导入1,这就是问题所在。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70250120

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档