Achim
Achim

Reputation: 247

Causing an error by creating a monorepo with circular dependencies

I'm relatively new to monrepo's/yarn workspaces/lerna. I was working on a React / TypeScript monorepo where I cleaned up circular dependencies. I just think they shouldn't exist in a clean code architecture. I know that they make life easier when you want to refactor parts of an app, study the app's architecture or just want to reference one of the repo's in another project.

But can someone provide a good example of where a circular dependency is actually causing an error in a TypeScript/React project? Probably related to importing Types in a circular way, or somewhere else?

Many thanks in advance!

Achim

Upvotes: 0

Views: 1762

Answers (1)

t1gor
t1gor

Reputation: 1292

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 imported in module B
  • Module B is imported in module C
  • Module C imports 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!

Upvotes: 1

Related Questions