From 3ff816afa6d8dd0832cc6b384e0c62a77f78b4e1 Mon Sep 17 00:00:00 2001 From: PatrickJS Date: Wed, 7 Sep 2016 14:09:25 -0700 Subject: [PATCH] style(CompileMetadataResolver): better error message (#11401) --- .../@angular/compiler/src/metadata_resolver.ts | 4 +++- .../test/linker/ng_module_integration_spec.ts | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/modules/@angular/compiler/src/metadata_resolver.ts b/modules/@angular/compiler/src/metadata_resolver.ts index 0c71523f4e..50e265eb93 100644 --- a/modules/@angular/compiler/src/metadata_resolver.ts +++ b/modules/@angular/compiler/src/metadata_resolver.ts @@ -377,7 +377,9 @@ export class CompileMetadataResolver { const oldModule = this._ngModuleOfTypes.get(type); if (oldModule && oldModule !== moduleType) { throw new Error( - `Type ${stringify(type)} is part of the declarations of 2 modules: ${stringify(oldModule)} and ${stringify(moduleType)}!`); + `Type ${stringify(type)} is part of the declarations of 2 modules: ${stringify(oldModule)} and ${stringify(moduleType)}! ` + + `Please consider moving ${stringify(type)} to a higher module that imports ${stringify(oldModule)} and ${stringify(moduleType)}. ` + + `You can also create a new NgModule that exports and includes ${stringify(type)} then import that NgModule in ${stringify(oldModule)} and ${stringify(moduleType)}.`); } this._ngModuleOfTypes.set(type, moduleType); } diff --git a/modules/@angular/core/test/linker/ng_module_integration_spec.ts b/modules/@angular/core/test/linker/ng_module_integration_spec.ts index d193e22e53..904106ab36 100644 --- a/modules/@angular/core/test/linker/ng_module_integration_spec.ts +++ b/modules/@angular/core/test/linker/ng_module_integration_spec.ts @@ -168,7 +168,9 @@ function declareTests({useJit}: {useJit: boolean}) { expect(() => createModule(Module2)) .toThrowError( - `Type ${stringify(SomeDirective)} is part of the declarations of 2 modules: ${stringify(Module1)} and ${stringify(Module2)}!`); + `Type ${stringify(SomeDirective)} is part of the declarations of 2 modules: ${stringify(Module1)} and ${stringify(Module2)}! ` + + `Please consider moving ${stringify(SomeDirective)} to a higher module that imports ${stringify(Module1)} and ${stringify(Module2)}. ` + + `You can also create a new NgModule that exports and includes ${stringify(SomeDirective)} then import that NgModule in ${stringify(Module1)} and ${stringify(Module2)}.`); }); it('should error if a directive is declared in more than 1 module also if the module declaring it is imported', @@ -183,7 +185,9 @@ function declareTests({useJit}: {useJit: boolean}) { expect(() => createModule(Module2)) .toThrowError( - `Type ${stringify(SomeDirective)} is part of the declarations of 2 modules: ${stringify(Module1)} and ${stringify(Module2)}!`); + `Type ${stringify(SomeDirective)} is part of the declarations of 2 modules: ${stringify(Module1)} and ${stringify(Module2)}! ` + + `Please consider moving ${stringify(SomeDirective)} to a higher module that imports ${stringify(Module1)} and ${stringify(Module2)}. ` + + `You can also create a new NgModule that exports and includes ${stringify(SomeDirective)} then import that NgModule in ${stringify(Module1)} and ${stringify(Module2)}.`); }); it('should error if a pipe is declared in more than 1 module', () => { @@ -199,7 +203,9 @@ function declareTests({useJit}: {useJit: boolean}) { expect(() => createModule(Module2)) .toThrowError( - `Type ${stringify(SomePipe)} is part of the declarations of 2 modules: ${stringify(Module1)} and ${stringify(Module2)}!`); + `Type ${stringify(SomePipe)} is part of the declarations of 2 modules: ${stringify(Module1)} and ${stringify(Module2)}! ` + + `Please consider moving ${stringify(SomePipe)} to a higher module that imports ${stringify(Module1)} and ${stringify(Module2)}. ` + + `You can also create a new NgModule that exports and includes ${stringify(SomePipe)} then import that NgModule in ${stringify(Module1)} and ${stringify(Module2)}.`); }); it('should error if a pipe is declared in more than 1 module also if the module declaring it is imported', @@ -214,7 +220,9 @@ function declareTests({useJit}: {useJit: boolean}) { expect(() => createModule(Module2)) .toThrowError( - `Type ${stringify(SomePipe)} is part of the declarations of 2 modules: ${stringify(Module1)} and ${stringify(Module2)}!`); + `Type ${stringify(SomePipe)} is part of the declarations of 2 modules: ${stringify(Module1)} and ${stringify(Module2)}! ` + + `Please consider moving ${stringify(SomePipe)} to a higher module that imports ${stringify(Module1)} and ${stringify(Module2)}. ` + + `You can also create a new NgModule that exports and includes ${stringify(SomePipe)} then import that NgModule in ${stringify(Module1)} and ${stringify(Module2)}.`); }); });