fix(referral): wrap LiquidityManagementModule import in forwardRef to break circular dependency#4220
Merged
Conversation
… break circular dependency AccountingModule (#3880) is now the first module in core.module.ts to require LiquidityManagementModule, which transitively re-enters ReferralModule (via BankModule -> UserModule) before finishing its own export. ReferralModule's own unwrapped LiquidityManagementModule import then captures undefined, crashing Nest bootstrap ("Nest cannot create the ReferralModule instance") on every restart in DEV.
TaprootFreak
approved these changes
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AccountingModule) landed:Nest cannot create the ReferralModule instance/The module at index [9] of the ReferralModule "imports" array is undefined, repeating on every restart attempt.AccountingModuleis now the first import incore.module.ts, and is the first thing to requireLiquidityManagementModule. That require transitively re-entersReferralModule(viaLiquidityManagementModule -> BankModule -> UserModule -> ReferralModule) beforeLiquidityManagementModule's own file finishes exporting.ReferralModule's existing, unwrappedLiquidityManagementModuleimport then capturesundefinedat decorator-evaluation time — a classic CommonJS circular-require hazard, not a runtime bug.forwardRef(), matching the patternReferralModulealready uses for its other circular deps (UserModule,TransactionModule) in the same file.Verification
dist/offorigin/developunmodified and rannode dist/src/main.js— got the identicalReferralModulecrash and scope trace seen in DEV logs.npx jest --testPathPattern="(referral|liquidity-management|accounting)"— 36 suites / 738 tests passed.Test plan
dfx-apicontainer stops crash-looping / all Kuma DEV child monitors recover