Repository navigation
Description
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
jwuliger commentedon Oct 27, 2017
Having the same issue here with a project that is heavy on NgModules. I cant serve the app.
filipesilva commentedon Oct 27, 2017
Heya, I opened this issue over in angular/angular#19979, since that's the home of the
@angular/compilerpackage.angular-automatic-lock-bot commentedon Sep 7, 2019
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.