Repository navigation
Description
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
SatyaCOD commentedon Nov 6, 2017
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
MartinFreire commentedon Nov 21, 2017
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 serveworks fine. But when I add my modules it get this error: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
I'm using:
Windows 10 - 16Gb of RAM
Node v8.9.1
Angular CLI v1.5.3
I hope it can help.
Regards
fix(compiler): report an error for recursive module references
fix(compiler): report an error for recursive module references
angular-automatic-lock-bot commentedon Sep 13, 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.