Skip to content

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

Closed

Description

@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. jwuliger commented on Oct 27, 2017

    @jwuliger

    Having the same issue here with a project that is heavy on NgModules. I cant serve the app.

  2. filipesilva commented on Oct 27, 2017

    @filipesilva
    Contributor

    Heya, I opened this issue over in angular/angular#19979, since that's the home of the @angular/compiler package.

  3. angular-automatic-lock-bot commented on Sep 7, 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.

  4. locked and limited conversation to collaborators on Sep 7, 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

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions