Circular Dependencies
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
Solution: Circular Dependencies
@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
Trust Score
6 verifications
- 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
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
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
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
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep