FG
๐Ÿ’ป Software๐Ÿ—„๏ธ Databases

Circular Dependencies

Freshover 5 years ago
Mar 14, 20260 views
Confidence Score74%
74%

Problem

Issue type: [x] question [ ] bug report [ ] feature request [ ] documentation issue TypeORM version: [x] `latest` [ ] `@next` [ ] `0.x.x` (or put your version here) Bi-directional relations are circular by definition. With webpack and typescript on the backend, how can we possibly solve this issue? Are we actually forced into keeping one giant awful `allEntities.ts` file?... I know it's not a typeorm problem, but ES modules don't support circular dependencies, and here we have a fantastic ORM library which basically requires them? I honestly don't understand how anyone can use this, the problem seems so fundamental... Can the maintainers of this library offer any help or solution? Thanks :)

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
High Confidence Fix
74% confidence100% success rate6 verificationsLast verified Mar 14, 2026

Solution: Circular Dependencies

Low Risk

@Ginden Sorry, I'm abusing the word "support" here. I'm aware that circular dependencies work, as in, you can compile them, and if you carefully use things in the right order, that it's all ๐Ÿ’ฏ(that is, until some future day when you refactor some code and now some other part is using a circular-required module before it's fully loaded, which you have absolutely no way to test for or maybe even kno

74

Trust Score

6 verifications

100% success
  1. 1

    @Ginden Sorry, I'm abusing the word "support" here. I'm aware that circular depe

    @Ginden Sorry, I'm abusing the word "support" here. I'm aware that circular dependencies work, as in, you can compile them, and if you carefully use things in the right order, that it's all ๐Ÿ’ฏ(that is, until some future day when you refactor some code and now some other part is using a circular-required module before it's fully loaded, which you have absolutely no way to test for or maybe even know about, until it blows up at runtime). This fragile load order is very difficult to maintain in a complex codebase.

  2. 2

    The best way, also as pointed out by the link you've shared, is to avoid circula

    The best way, also as pointed out by the link you've shared, is to avoid circular dependencies completely. We can use tools like the circular-dependency-plugin or madge to detect them before they happen. But if we do that, then how can we possibly have a many-to-many entity relationship, which is circular by nature, and would be disallowed by our newly adopted toolset?

  3. 3

    How can one feasibly avoid circular dependencies completely and at the same time

    How can one feasibly avoid circular dependencies completely and at the same time use typeorm entity relationships?

  4. 4

    I know this isn't a typeorm-code problem, but the design of typeorm certainly pu

    I know this isn't a typeorm-code problem, but the design of typeorm certainly puts users in a difficult position.

Validation

Resolved in typeorm/typeorm GitHub issue #4526. Community reactions: 28 upvotes.

Verification Summary

Worked: 6
Partial: 2
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

typeormormtypescript