Solvedangular RangeError: Maximum call stack size exceeded
✔️Accepted Answer
I love the writeup. I wish all errors would be written up so well! Thank you for making our life easy.
This is a known issue and it has to do with minification. In short the minification is broken in Angular as of right now. The fix will come as part of #6567 in a week or so. The issue is that when the minfier munges the code the classes get renamed and collide. <second-level-component>
then gets added recursively which causes a stack overflow.
Other Answers:
when you are using lazyload, don't forget below conf:
@NgModule({
imports: [
RouterModule.forChild(ROUTES)
]
})
I had the same problem and SOLVED my problem. I accedentally imported the same module which is TravelsModule in TravelsModule.. :) Recursive import results this probem. I removed that import and my problem is solved. My problem was not related to any minified files.. As an example, I pasted it below and commented wrong line..
@NgModule({
imports: [
CommonModule,
RouterModule,
//TravelsModule, <----- This line causes the problem
],
declarations: [
],
providers: [
],
exports: [
]
})
export class TravelsModule {}
Uncaught RangeError: Maximum call stack size exceeded
at Object.U (http://localhost:4200/main.bundle.js:55401:126)
at Object.Type (http://localhost:4200/main.bundle.js:37:146)
at isValidType (http://localhost:4200/main.bundle.js:24279:157)
at http://localhost:4200/main.bundle.js:23808:25
at Array.forEach (native)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:4200/main.bundle.js:23806:44)
at http://localhost:4200/main.bundle.js:23819:50
at Array.forEach (native)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:4200/main.bundle.js:23806:44)
at http://localhost:4200/main.bundle.js:23819:50(anonymous function) @ main.bundle.js:55401(anonymous function) @ index.js:1isValidType @ metadata_resolver.js:685(anonymous function) @ metadata_resolver.js:214CompileMetadataResolver.getNgModuleMetadata @ metadata_resolver.js:212(anonymous function) @
....
....
....
metadata_resolver.js:212(anonymous function) @ metadata_resolver.js:225CompileMetadataResolver.getNgModuleMetadata @ metadata_resolver.js:212(anonymous function) @ metadata_resolver.js:225CompileMetadataResolver.getNgModuleMetadata @ metadata_resolver.js:212(anonymous function) @ metadata_resolver.js:225
@bvaughn Brian! Thank you! Just wanted to confirm that I am a fellow angular 2/webpack user, and I've been trying to fix this for days, and your solution definitely helped! Thanks!
The same error I was getting because in the child module I was trying to call my initial child component by using below way.
bootstrap: [ChildFirstComponent] -----------------in my Child Module.
So instead I created ChildRoute and from there I called my ChildFirstComponent like below.
#######################
const childRoutes:Routes=[
{path:'',component:ChildComponent},
]
@NgModule({
imports:[RouterModule.forChild(childRoutes)
)],
exports:[RouterModule]
})
##############################
Note:Use RouterModule.forChild() in the import array while you are creating child route files
It seems incredibly easy to cause an infinite loop in a production Angular 2 app. The following example code is the most simplified reproduction case I could come up with. In dev mode, it displays what you would expect and logs the following text:
In production mode the
SecondLevelComponent
gets recreated until the stack overflows. (The "SecondLevelComponent.constructor" message prints on loop.)Removing either of the un-used public methods (
someMethod
) causes the problem to go away.This is an over-simplification but it's essentially what I'm trying to do for the bvaughn/ng2-virtualized demo app. The app works fine when running locally, in dev-mode. But the static production build (visible here) fails.
Steps to reproduce and a minimal demo of the problem
Here's a Plnkr: https://plnkr.co/edit/5kHjjmkWbYpi7y8nHTqL?p=preview
And here's the source code:
HTML
JavaScript
Runtime error