-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to resolve "Circular dependency" in NRWL #2570
Comments
U can't doing something like: //LIB B |
Thanks, Yeah I am using in the same way, I have created a service 'LIB_XYZ which has the methods and I am using in other libraries, but still getting an error |
If you use What @czaplej mentioned about creating a 3rd library works a lot of the time. I wrote an initial doc in the wiki on resolving circular dependencies: https://github.com/nrwl/nx/wiki/Resolving-Circular-Dependencies Let me know if it helps. |
Anyway, something happened that NX started posting linter errors? I didn't change anything in my project, "only" updated from 8 to 9 and linter started throwing circular dep errors (same |
I have similar errors that @kkuriata said. I have use 9.0.4 version of nx |
I think @kkuriata is right. I'm also seeing the circular dependency issues after upgrading to 9. |
I have manually updated the code by removing which has a circular dependency, It works fine now, Actually, all libraries are interrelated, so if one has dependency most of the other related are also failing |
I getting false positives of I have this graph Where each of the akita-ng-libraries have akita as a I also have a demo app which uses all of the above (remember peerDependencies) which causes the graph to look like this and now I'm getting spammed with false
please advice |
I'm facing difficulties understanding how to best structure my NX workspace in apps and libs to optimize build times and benefit from caching, considering an Angular + NGRX app. As the starting point, I had one "web" app, composed of many major "features", each with its own (lazy-loaded) Angular module. Those modules were loaded lazily through the router, but also eagerly when a dependent Angular module needed it (e.g., if module X needs module Y, it has it in its imports). As part of my current refactoring, I've extracted most of those features in separate libraries: one per major feature of the app, which I load lazily when needed. Now, after fixing compilation issues, I remain with circular dependencies. My question is: what is your experience with splitting inter-dependent lazy-loaded Angular modules and what would be your recommendation? Do you recommend splitting each feature in multiple libs (e.g., feature-x-core, feature-x-store, feature-x-dumb-components, feature-x-smart-components, ...)? I've given this some thought and I don't see a clear path forward. For instance, if I consider the NGRX selectors of feature-x, then I can see that those rely on state types and selectors from feature-y. One idea that I still have is extracting some parts (e.g., reducers & selectors) of the store for each feature and putting those in a shared "core" lib, but I'd still remain with the Angular module imports. Or should I just ignore the lint error in that case? In our case I feel like keeping all of those features in the same NX lib is detrimental as it represents > 80% of the whole app. |
Hi difficult to find why I have circular dependency! don't see any dependency from |
Yes, Nx is able to resolve more dependencies in 9 than before in 8. As a result, a dependency could have been resolved that now causes a circular dependency. These are valid dependencies. For example, Relative dependencies are now a resolved dependency even though they are not recommended. import { } from '../../libs/libA/src'; // Is now a dependency |
I'm going to close this issue as I've started a guide. https://github.com/nrwl/nx/wiki/Resolving-Circular-Dependencies Please open a new issue if that guide does not cover a method for resolving circular dependencies so we can add it. |
@FrozenPandaz in my i have a library called then i import some services from the |
@Abdallah-khalil You should move your environment files into some common library that will be imported by all the apps you need. You can then use fileReplacements in angular.json/workspace.json to replace specific environment for chosen build. Unfortunately when you want to use fileReplacements with default dev build ( For example, when I have two projects:
Then I use |
There's also the issue when using something like |
I updated the nx workspace recently, and I'm no longer seeing the circular dep errors. Can someone from nx team confirm if this is fixed or still a known issue? |
@Ponjimon That's a very good point, and one that is keeping me (wrongly or rightly) from having multiple modules for my TypeORM entities. |
Another possible scenario, which I have encountered, is when using NgRX Router Store, like in https://blog.nrwl.io/using-ngrx-4-to-manage-state-in-angular-applications-64e7a1f84b7b E.g. Thus a circular dependency. |
I have run into this exact situation! Slightly less complex however. I am using a lib that container my auth store, its being used in the login feature lib. I want to use the navigated helper to generate a cookie when the login component is loaded however this is a direct circular dependancy. I see no way around this.... that is if i am going to the navigated helper..... |
so it sounds like some of these circular dependencies are just saying HE... he is using some stuff from HER but as long as it executes fine there should be no problem unless these circular dependencies are warning of an infinite loop? I think the definition of circular dependency needs to be revisited maybe these are just BIDIRECTIONAL ASSOCIATIONS which may be harmless and a REAL circular dependency means INFINITE LOOP imminent any thoughts ? can someone elaborate simply confirming somethings I noted here ? |
Adding to what @ghost said, it seems that a circular dependency is unavoidable when using the navigation operator in an effect, if the component that the operator references is not in the same module (or lib) as the effect. In my case, the component communicates exclusively with a facade in a data access lib to get its data. But after switching my effect to use the router as the source of truth as recommended in the article previously cited, the effect in the the data access lib references back to the component in the ui lib. Guaranteed circular dependency. Splitting apart data access libs from ui libs isn't an anti-pattern, but perhaps there is some nuance I'm not appreciating. Any insights or best practices are welcome. Thanks. |
Can someone elaborate a comprehensive separation solution for this?
my @shared-root-data-access lib project has the following tags
my @shared-feature-notification library has the following tags
How can my effects send a Ionic toaster UI notification message to the UI if I am forced to separate everything with eslint? Does anyone see a solution? I would hate to have to remodel my notifications feature with its own data-access just to get messages to the UI thru a de-coupled dispatch action but would rather just use it right in my effects. Do I have a choice here? Im also seeing the same twangle with services which I separated into a shared-root-service library yielding this
when my effects enjoy full usage of services & router all over the codebase Victors book on this is awesome Im stunned its 2018 and barely any of this stuff is being applied in the field from my camp... and Im doing all I can to bring Nx to the field... and only met with indifference fear but I prototype it for every assignment to prove... tech leads have been obsoleted overnight now (by the Nx masterpiece) and stuck on what they only know and afraid to peek at. Nx is the final way.... trying to see it all thru (the circular dependencies prevention model) I think this is the final jump more needs to be said and shown the airlines repo as generous (and thanks guys awesome push) as it was doesn't go deep enough code growth wise to actually see this play out.... with services, features getting tangles up with data-access and effects. If everything NEEDs to be separated by de-coupled dispatches then I think I get it. But if data-access library project uses services library (which is what effects enjoy) and service library project dispatches actions (which is reasonable) ... its locked down wont compile with circular dependency. A confirmation would be nice. thanks in advance |
It work for me. nx dep-graph After adding this, the graph is the same. It look like same problem at #9085 Here is my package.json. "devDependencies": {
"@nrwl/angular": "^14.7.5",
"@nrwl/cli": "14.7.5",
"@nrwl/cypress": "14.7.5",
"@nrwl/eslint-plugin-nx": "14.7.5",
"@nrwl/jest": "14.7.5",
"@nrwl/linter": "14.7.5",
"@nrwl/nest": "^14.7.5",
"@nrwl/node": "14.7.5",
"@nrwl/nx-cloud": "latest",
"@nrwl/workspace": "14.7.5",
"@types/jest": "28.1.1",
"@types/node": "16.11.7",
"nx": "14.7.5",
"ts-node": "10.9.1",
"typescript": "~4.8.2"
},
"dependencies": {
"@angular/core": "~14.2.0",
"@nestjs/core": "^9.0.0",
} |
I was receiving false positive circular dep. error. Solution for me was to run |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
I am getting the below LINT error
"Circular dependency between "A(lib)" and "B(lib)" detected (nx-enforce-module-boundaries) tslint error"
Most of the issues are coming when a Service from one Library is used(imported) in another lib.
Can you please help how to resolve this issue
The text was updated successfully, but these errors were encountered: