Search code examples
angularnativescriptangular-nativescript

ReferenceError: Cannot access 'FacilityModule' before initialization - after migrating from ng8 to ng10


I am working in an angular 10 nativescript monorepo and was porting over components from a previous angular 8 only codebase.

After porting of FacilityModule and lazy loading in new codebase I receive the following error.

ReferenceError: Cannot access 'FacilityModule' before initialization 

I have referenced several previous angular stack overflow questions and many of them pointed to an issue where FacilityModule is being manually imported in a service then used in the providedIn field ultimately causing a circular dependency. I have checked the entire code base via search and the FacilityModule is only imported in my app-routing.module.ts as a lazy loaded import.

I also locally ran the madge npm package to check for circular dependencies in my project and it said none were present.

Any ideas on other things in ng10 that could be causing this issue? Thanks for the help in advance.

Same code worked before in ng 8 application so figured it's something that ng 10 doesn't like.


Solution

  • This happens when you have a circular dependency inside your app. Somewhere a provider is duplicated.

    Please see: Angular dependency with "providedIn" in lazy loading modules