問題描述
通過創建具有循環依賴關係的 monorepo 導致錯誤 (Causing an error by creating a monorepo with circular dependencies)
我對 monrepo/yarn workspaces/lerna 比較陌生。我正在研究一個 React / TypeScript monorepo,我在其中清理了循環依賴項。我只是認為它們不應該存在於乾淨的代碼架構中。我知道當您想要重構應用程序的某些部分、研究應用程序的架構或只是想在另一個項目中引用其中一個存儲庫時,它們會讓生活更輕鬆。
但是有人可以提供一個很好的例子來說明哪裡循環依賴實際上導致 TypeScript/React 項目中的錯誤?可能與以循環方式或其他方式導入類型有關?
非常感謝!
Achim
參考解法
方法 1:
We had several circular dependencies in our project, which were related to the differences in bundlers (babel
for react
& metro
for react‑native
).
But can someone provide a good example of where a circular dependency is actually causing an error in a TypeScript/React project?
Sure, consider the following:
- Module A is
import
ed in module B - Module B is
import
ed in module C - Module C
import
s module A
This way the modules dependencies can not be resolved, at least not correctly.
I just think they shouldn't exist in a clean code architecture.
That is for sure true :) Keep it up!