question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Circular dependency when trying to import shared components into shell module (SharedModule <-> ShellModule).

See original GitHub issue

I want to use ish-content-include to make it possible for the client to edit the header navigation menu items. However to use ish-content-include I have to import sharedModule into shellModule. ShellModule already is being imported by sharedModule, so when i import sharedModule they will depend on eachother creating a circular dependency and giving the error Maximum call stack exceeded.

How can I solve this issue?

image image image

Note: This will be used as reference and discussed tomorrow with the internal intershop team

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
dhhyicommented, Feb 22, 2021

Hi @adrianResler,

For example I would need to use ProductQuantityComponent in MiniBasket that is part of shellModules in order to change lineItem quantity from the MiniBasket overlay level

Yes, if this PR is merged, it should be possible to do this for any component in the shared module by calling the lazy-component schematic. With your example:

ng g lazy-component src/app/shared/components/product/product-quantity/product-quantity.component.ts

For projects this is a good approach and nothing really speaks against it. By adding lazy component wrappers to the shell the initial bundle doesn’t grow as significantly as moving components to the shell module would do. But if this is overused, the code can become quite unreadable.

For the PWA itself I’d rather propose a refactoring and lazy-fy the line item list for the mini-basket in #528 like you just inspired me to do:

https://github.com/intershop/intershop-pwa/blob/e2f1574d5a1a951106b8673d1461b1937ab38174/src/app/shell/header/mini-basket/mini-basket.component.html#L18-L20

That way also the ish-product-image component can be moved to the shared module so the initial bundle gets smaller.

2reactions
ismail-codinglabcommented, Feb 18, 2021

I have taken a good look at it and tried to de-couple shellModule from sharedModule. However as i kept decoupling i found out there’s a decision being made a while ago which makes this quite a big investment to decouple.

The shellModule in my opinion should not be treated as a sharedModule, it should not be a “foundation” for another module. It should be a dead-end for header/footer/whatever. While I do have an opinion on a business perspective this isn’t feasible because of the time investment.

so we are going with the provided route of something like https://github.com/intershop/intershop-pwa/pull/496.

Thank you for your time and for the quick replies!

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular --Import sharedModule inside the coreModule without ...
I'm not seeing a circular reference here. · feature and shared modules do not import core but shared components do use singleton services...
Read more >
NG0200: Circular dependency in DI detected while ... - Angular
You will be able to see if any child dependencies rely on the original file by mapping out the component, module, or service's...
Read more >
How to fix nasty circular dependency issues once and for all in ...
In the many projects I have maintained so far, sooner or later I always run into the same issue: circular module dependencies.
Read more >
How to resolve "Circular dependency" in NRWL #2570 - GitHub
I am getting the below LINT error. "Circular dependency between "A(lib)" and "B(lib)" detected (nx-enforce-module-boundaries) tslint error"
Read more >
Circular Dependency Nightware : r/Nestjs_framework - Reddit
I'm gonna try do this suggestion of the shared/core module where all of my services and models will only be imported into the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found