Skip to content

ERROR in RangeError: Maximum call stack size exceeded on production build and faulty export on module #19979

Closed

Description

@filipesilva

Moved over from angular/angular-cli#8187, opened by @BartNetJS.


Bug Report or Feature Request (mark with an x)

- [x] bug report 
- [ ] feature request

Versions.

@angular/cli: 1.4.9
node: 8.7.0
os: win32 x64
@angular/animations: 4.4.6
@angular/common: 4.4.6
@angular/compiler: 4.4.6
@angular/core: 4.4.6
@angular/forms: 4.4.6
@angular/http: 4.4.6
@angular/platform-browser: 4.4.6
@angular/platform-browser-dynamic: 4.4.6
@angular/router: 4.4.6
@angular/cli: 1.4.9
@angular/compiler-cli: 4.4.6
@angular/language-service: 4.4.6
typescript: 2.3.4

Repro steps.

Create a module and export the same module in the export tag (this is the fault)

@NgModule({
  imports: [CommonModule],
  exports: [ MyFaultyModule ],
  declarations: [MyFaultyComponent],
  providers: [],
})
export class MyFaultyModule { }

Build a production build:
ng build --prod

The log given by the failure.

ERROR in RangeError: Maximum call stack size exceeded
at StaticReflector.annotations (PathRemovedForDemo\node_modules@angular\compiler\bundles\compiler.umd.js:1:1)
at NgModuleResolver.resolve (PathRemovedForDemo\node_modules@angular\compiler\bundles\compiler.umd.js:14750:70)
at CompileMetadataResolver.getNgModuleMetadata (PathRemovedForDemo\node_modules@angular\compiler\bundles\compiler.umd.js:15402:60)
at CompileMetadataResolver.getNgModuleSummary (PathRemovedForDemo\node_modules@angular\compiler\bundles\compiler.umd.js:15358:52)
at PathRemovedForDemo\node_modules@angular\compiler\bundles\compiler.umd.js:15450:68
at Array.forEach ()
at CompileMetadataResolver.getNgModuleMetadata (PathRemovedForDemo\node_modules@angular\compiler\bundles\compiler.umd.js:15445:49)
at CompileMetadataResolver.getNgModuleSummary (PathRemovedForDemo\node_modules@angular\compiler\bundles\compiler.umd.js:15358:52)
at PathRemovedForDemo\node_modules@angular\compiler\bundles\compiler.umd.js:15450:68
at Array.forEach ()
at CompileMetadataResolver.getNgModuleMetadata (PathRemovedForDemo\node_modules@angular\compiler\bundles\compiler.umd.js:15445:49)
at CompileMetadataResolver.getNgModuleSummary (PathRemovedForDemo\node_modules@angular\compiler\bundles\compiler.umd.js:15358:52)
at PathRemovedForDemo\node_modules@angular\compiler\bundles\compiler.umd.js:15450:68
at Array.forEach ()
at CompileMetadataResolver.getNgModuleMetadata (PathRemovedForDemo\node_modules@angular\compiler\bundles\compiler.umd.js:15445:49)
at CompileMetadataResolver.getNgModuleSummary (PathRemovedForDemo\node_modules@angular\compiler\bundles\compiler.umd.js:15358:52)

Desired functionality.

The ng cli should detect this fault and report the module that causes the call stack exception

Mention any other details that might be useful.

The issue can be found in compile.umd.js:
function: **CompileMetadataResolver.prototype.getNgModuleMetadata **
On the code:

 if (meta.exports) {
            flattenAndDedupeArray(meta.exports).forEach(function (exportedType) {
                if (!isValidType(exportedType)) {
                    _this._reportError(syntaxError("Unexpected value '" + stringifyType(exportedType) + "' exported by the module '" + stringifyType(moduleType) + "'"), moduleType);
                    return;
                }
                var /** @type {?} */ exportedModuleSummary = _this.getNgModuleSummary(exportedType);                 if (exportedModuleSummary) {
                    exportedModules.push(exportedModuleSummary);
                }
                else {
                    exportedNonModuleIdentifiers.push(_this._getIdentifierMetadata(exportedType));
                }
            });
        }

var exportedModuleSummary = _this.getNgModuleSummary(exportedType);
=> this cause the recursion and endless loop because 'getNgModuleMetadata ' is called again for the same module

So my suggestion is watch how deep the recusion is going, and for example start logging warnings when reached 5 nested call.
Something like this:

CompileMetadataResolver.prototype.getNgModuleMetadata = function (moduleType, throwIfNotFound, nested = 0) {
        nested++;
        if(nested > 4) console.warn(´nested module {moduleType.name} (level: ${nested})´)

of course function calling getNgModuleMetadata should be modified to.

Can someone on the core cli team confirm this is a good approach?

Another approach is of course checking for the module name that is calling it self, but suppose you have something like this moduleX=>export moduleY=>exportmoduleX...

If so, I will create a pull request

Activity

  1. SatyaCOD commented on Nov 6, 2017

    @SatyaCOD

    We had this same issue. Our app is private and I have no idea what causes this issue. We have downgraded back to Angular 4.4.6

    We tried typescript 2.6.1 and typescript 2.4.2 . Issue occurs no matter what when using Angular 5

    Wish I could offer more details

  2. added
    area: coreIssues related to the framework runtime
    regressionIndicates than the issue relates to something that worked in a previous version
    on Nov 9, 2017
  3. MartinFreire commented on Nov 21, 2017

    @MartinFreire

    Hi, I'm having the same issue with an app that is growing each day.
    I'm using a template called Fuse and I'm updating to version 1.2.1 (that updates Angular to version 5)

    Using a blank template ng serve works fine. But when I add my modules it get this error:

    ERROR in RangeError: Maximum call stack size exceeded
        at Set.add (native)
        at new Set (<anonymous>)
        at dedupeArray (PROJECT_FOLDER\node_modules\@angular\compiler\bundles\compiler.umd.js:15903:27)
        at flattenAndDedupeArray (PROJECT_FOLDER\node_modules\@angular\compiler\bundles\compiler.umd.js:15912:12)
        at CompileMetadataResolver.getNgModuleMetadata (PROJECT_FOLDER\node_modules\@angular\compiler\bundles\compiler.umd.js:15114:13)
        at CompileMetadataResolver.getNgModuleSummary (PROJECT_FOLDER\node_modules\@angular\compiler\bundles\compiler.umd.js:15041:52)
        at PROJECT_FOLDER\node_modules\@angular\compiler\bundles\compiler.umd.js:15129:72    at Array.forEach (<anonymous>)
        at CompileMetadataResolver.getNgModuleMetadata (PROJECT_FOLDER\node_modules\@angular\compiler\bundles\compiler.umd.js:15114:49)
        at CompileMetadataResolver.getNgModuleSummary (PROJECT_FOLDER\node_modules\@angular\compiler\bundles\compiler.umd.js:15041:52)
        at PROJECT_FOLDER\node_modules\@angular\compiler\bundles\compiler.umd.js:15129:72    at Array.forEach (<anonymous>)
        at CompileMetadataResolver.getNgModuleMetadata (PROJECT_FOLDER\node_modules\@angular\compiler\bundles\compiler.umd.js:15114:49)
        at CompileMetadataResolver.getNgModuleSummary (PROJECT_FOLDER\node_modules\@angular\compiler\bundles\compiler.umd.js:15041:52)
        at PROJECT_FOLDER\node_modules\@angular\compiler\bundles\compiler.umd.js:15129:72    at Array.forEach (<anonymous>)
    

    After reading some problems of other people, I try seeing what happened to the memory consumption and I notice that the compiler crashes every time it went beyond the 500mb

    image

    I'm using:
    Windows 10 - 16Gb of RAM
    Node v8.9.1
    Angular CLI v1.5.3

    I hope it can help.
    Regards

  4. added and removed
    regressionIndicates than the issue relates to something that worked in a previous version
    on Dec 15, 2017
  5. self-assigned this
    on Dec 15, 2017
  6. added 2 commits that reference this issue on Dec 20, 2017
    ced575f
    33c0ee3
  7. angular-automatic-lock-bot commented on Sep 13, 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.

  8. locked and limited conversation to collaborators on Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions