style(CompileMetadataResolver): better error message (#11401)
This commit is contained in:
parent
dd03bf12e1
commit
3ff816afa6
|
@ -377,7 +377,9 @@ export class CompileMetadataResolver {
|
||||||
const oldModule = this._ngModuleOfTypes.get(type);
|
const oldModule = this._ngModuleOfTypes.get(type);
|
||||||
if (oldModule && oldModule !== moduleType) {
|
if (oldModule && oldModule !== moduleType) {
|
||||||
throw new Error(
|
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);
|
this._ngModuleOfTypes.set(type, moduleType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,9 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
|
|
||||||
expect(() => createModule(Module2))
|
expect(() => createModule(Module2))
|
||||||
.toThrowError(
|
.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',
|
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))
|
expect(() => createModule(Module2))
|
||||||
.toThrowError(
|
.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', () => {
|
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))
|
expect(() => createModule(Module2))
|
||||||
.toThrowError(
|
.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',
|
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))
|
expect(() => createModule(Module2))
|
||||||
.toThrowError(
|
.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)}.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue