Skip to content

ERROR in Maximum call stack size exceeded : Feature module circular dependency  #6309

Closed

Description

@vaibhavbparikh

Bug Report or Feature Request (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.0.0-rc.2
node: 6.10.0
os: linux x64
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/core: 2.4.10
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
@angular/cli: 1.0.0-rc.2
@angular/compiler-cli: 2.4.10

Repro steps.

STEPS TO REPRODUCE
See git repo
https://github.com/vaibhavbparikh/circular-routes

The log given by the failure.

** NG Live Development Server is running on http://localhost:4200 **
Hash: f669143e24ec08ff9586
Time: 23223ms
chunk {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 232 kB {4} [initial] [rendered]
chunk {1} main.bundle.js, main.bundle.js.map (main) 332 kB {3} [initial] [rendered]
chunk {2} styles.bundle.js, styles.bundle.js.map (styles) 304 kB {4} [initial] [rendered]
chunk {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 5.64 MB [initial] [rendered]
chunk {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
ERROR in Maximum call stack size exceeded
webpack: Failed to compile.

However when I do any changes in file and save it again, angular-cli compiles it again and it runs fine then.

Desired functionality.

This behaviour shall not create cyclic dependency, there should be mechanism to detect this and break.
Either it shall not compile at all or it shall not throw error at first compile.

** USE CASE **

I have 3 Feature modules in the application. Each Feature modules contains 3 or more sub feature modules with their own components and specially routes with router module.
Now consider below scenario.
I have modules as below.

  • Feature 1
    • Feature1Sub Feature 1
    • Feature1Sub Feature 2
  • Feature 2
    • Feature2Sub Feature 1
    • Feature2Sub Feature 2
  • Feature 3
    • Feature3Sub Feature 1
    • Feature3Sub Feature 2

Now Consider below flow.
I am loading Feature 1 -> Feature1Sub Feature 1. I want to load Feature2Sub Feature 1 directly from Feature1Sub Feature 1. Without loading whole Feature 2 module. Also, I need to maintain navigation flow with back button.
So I will need to write routes and load that module with loadchildren feature in module of Feature1Sub Feature 1.
Same way I want to load Feature1Sub Feature 1 directly from Feature2SubFeature 1 without loading whole Feature 2 module. So again I will need to write routes in Feature1Sub Feature 1 module.

As a complex and large application, there might be need to create flow where two or more modules needs each other with routing.

Mention any other details that might be useful.

Activity

  1. vaibhavbparikh commented on May 14, 2017

    @vaibhavbparikh
    Author

    #5427
    This is similar issue but it's scenario is different.

  2. self-assigned this
    on May 15, 2017
  3. added
    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
    on May 15, 2017
  4. vaibhavbparikh commented on May 15, 2017

    @vaibhavbparikh
    Author

    @sumitarora any tentative timeline for this issue?

  5. mikeumus commented on May 25, 2017

    @mikeumus
    Contributor

    I've been getting this error too and in the browser for angular/cli@1.0.3-1.0.5

    Uncaught RangeError: Maximum call stack size exceeded
        at http://localhost:9000/portal/assets/dist/vendor.bundle.js:124400:56
        at Array.forEach (native)
        at DirectiveResolver._mergeWithPropertyMetadata (http://localhost:9000/portal/assets/dist/vendor.bundle.js:124400:39)
        at DirectiveResolver.resolve (http://localhost:9000/portal/assets/dist/vendor.bundle.js:124381:29)
        at CompileMetadataResolver.getNonNormalizedDirectiveMetadata (http://localhost:9000/portal/assets/dist/vendor.bundle.js:125095:64)
        at CompileMetadataResolver._getEntryComponentMetadata (http://localhost:9000/portal/assets/dist/vendor.bundle.js:125804:45)
        at http://localhost:9000/portal/assets/dist/vendor.bundle.js:125131:59
        at Array.map (native)
        at CompileMetadataResolver.getNonNormalizedDirectiveMetadata (http://localhost:9000/portal/assets/dist/vendor.bundle.js:125131:22)
        at CompileMetadataResolver._getEntryComponentMetadata (http://localhost:9000/portal/assets/dist/vendor.bundle.js:125804:45)
    
  6. vaibhavbparikh commented on May 26, 2017

    @vaibhavbparikh
    Author

    @mikeumus Can you share more details about how you are getting this error?

  7. mikeumus commented on May 27, 2017

    @mikeumus
    Contributor

    Windows 7 Pro
    Angular 4.1.0
    Angular CLI 1.0.5

    The project still runs fine in Angular 2.4 / CLI 1.0.0-rc.2
    Max exceed error in browser with dev build ng build
    Max exceed in cli terminal with prod/AoT build.

  8. ricardotorre commented on Jun 5, 2017

    @ricardotorre

    I am also having these problem with latest versions, I also have a module referencing it self:
    Windows 10 Pro (Creators Update)
    Node 6.10.3
    Npm 3.10.10
    Angular 4.1.3
    Angular CLI 1.1.0

    The weird thing is that when I use watch mode and save a file it builds successfully

  9. added 4 commits that reference this issue on Jun 27, 2017
    66d4e33
    5614a99
    91a1da0
    db0f817
  10. 9 remaining items

  11. fearless23 commented on Oct 30, 2017

    @fearless23

    @vaibhavbparikh @filipesilva The lazy loaded or feature module must have a route declared.

    app.routing.ts --> path="lazy" loadchildren="../lazy/lazy.module#LazyModule"

    inside Lazy Module --> path=' ' component="lazyParentComponent"
    path='child' loadChildren='../child/child.module#childModule

    If we skip routing in lazy module or don`t give path to when lazy module is loaded it gives error

  12. AnthonyNahas commented on Nov 9, 2017

    @AnthonyNahas

    the ERROR in Maximum call stack size exceeded happens actually when you have some infinite loop in your code.

    I had the same problem with my routes.

    Scenario:
    i have a lazyloadmodule that does not bind any component to the view -->

    {
            path: 'home',
            loadChildren: './home#HomeModule',
            pathMatch: 'full'
        },
    

    ##Before: in HomeModule -->

    @NgModule({
        imports: [
           
            CommonModule
        ],
        declarations: [HomeComponent]
    })
    export class HomeModule {
    }
    

    ##After: (Solution) in HomeModule -->

    @NgModule({
        imports: [
            RouterModule.forChild([
                {path: '', component: HomeComponent, pathMatch: 'full'}
            ]),
            CommonModule
        ],
        declarations: [HomeComponent]
    })
    export class HomeModule {
    }
    

    i hope that could helps someone

  13. ricardotorre commented on Nov 10, 2017

    @ricardotorre

    in angular5 and cli 1.5 this is working without problems!

    And just a quick note, self referencing routes are a valid implementation when doing unlimited depth routes like:

    /root/subroute-type1/subroute-type1/.../subroute-typeN/

  14. christofferskog commented on Nov 15, 2017

    @christofferskog

    Still happening on 1.5.0, I've got a PageModule which reference itself in it's routing. It works if I remove the circular dependency, start the app and then add it again. But not if I stop the server and start it again with the circular dependency already there. How can I solve this?

    For reference, I have this router module:

    const routes: Routes = [
      {
        path: '',
        component: PageComponent,
        children: [
          {
            path: ':pageId',
            loadChildren: 'app/routes/+dashboard/routes/+pages/routes/+page/page.module#PageModule'
          }
        ]
      }
    ];
    
    @NgModule({
      imports: [RouterModule.forChild(routes)]
    })
    
    export class PageRouterModule {}
    

    Which is then imported into PageModule:

    @NgModule({
      imports: [
        PageRouterModule
      ],
      exports: [PageRouterModule],
      declarations: [PageComponent]
    })
    
    export class PageModule {}
    
  15. ricardotorre commented on Nov 15, 2017

    @ricardotorre

    are you using Angular 5? It works for me (I have a self reference too) since I upgraded to Angular 5.0.1 (I upgraded it alongside with CLI to 1.5.0 and Material to 5.0.0-rc0)

    I believe this is due to the new compile-cli from angular

  16. added a commit that references this issue on Apr 23, 2018
    647cbfe
  17. vugar005 commented on Sep 4, 2018

    @vugar005

    In my situation it was because feature module was not importing its child routes.
    This solved my issue.

  18. chaitanyagawande commented on Nov 7, 2018

    @chaitanyagawande

    In my situation, this issue occurred because same name of two components.

  19. appify-ArsalanJaved commented on Jan 29, 2019

    @appify-ArsalanJaved

    In my case i'ám using reactive forms and formControlName and ID was same that's why function oninput was calling in loop.

  20. vigneshTheDev commented on Apr 28, 2019

    @vigneshTheDev

    In my case, the changes were not reflecting in the browser. I had to save lazyModule and lazyRoutingModule again :|

  21. angular-automatic-lock-bot commented on Sep 9, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  22. locked and limited conversation to collaborators on Sep 9, 2019
  23. added a commit that references this issue on May 29, 2026
    7957a11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentfreq2: mediumtype: bug/fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions