diff --git a/packages/compiler/src/metadata_resolver.ts b/packages/compiler/src/metadata_resolver.ts index b64968eebe..f9d71b4fab 100644 --- a/packages/compiler/src/metadata_resolver.ts +++ b/packages/compiler/src/metadata_resolver.ts @@ -664,16 +664,18 @@ export class CompileMetadataResolver { } private _getTypeDescriptor(type: Type): string { - if (this.isDirective(type)) { - return 'directive'; - } + if (isValidType(type)) { + if (this.isDirective(type)) { + return 'directive'; + } - if (this.isPipe(type)) { - return 'pipe'; - } + if (this.isPipe(type)) { + return 'pipe'; + } - if (this.isNgModule(type)) { - return 'module'; + if (this.isNgModule(type)) { + return 'module'; + } } if ((type as any).provide) { diff --git a/packages/compiler/test/metadata_resolver_spec.ts b/packages/compiler/test/metadata_resolver_spec.ts index df9e3b1c3a..313d95c7d6 100644 --- a/packages/compiler/test/metadata_resolver_spec.ts +++ b/packages/compiler/test/metadata_resolver_spec.ts @@ -399,6 +399,18 @@ export function main() { expect(() => resolver.getNgModuleMetadata(ModuleWithComponentInBootstrap)).not.toThrow(); })); + + // #20049 + it('should throw a reasonable message when an invalid import is given', + inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => { + @NgModule({imports: [{ngModule: true as any}]}) + class InvalidModule { + } + + expect(() => { resolver.getNgModuleMetadata(InvalidModule); }) + .toThrowError( + `Unexpected value '[object Object]' imported by the module 'InvalidModule'. Please add a @NgModule annotation.`); + })); }); it('should dedupe declarations in NgModule',