当试图在用户模型和组之间建立链接时,会发生以下错误:
我不明白为什么..。
[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:在添加
@Expose()
@HasMany(() => Group)
groups: Group[];转到user.model.ts
发布于 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,这就是问题所在。
https://stackoverflow.com/questions/70250120
复制相似问题