ng2-pdf-viewer breaks the AOT build with Angular CLI 1.5.0

Updated the Angular version to 5.0 in my existing project and it stopped working.
Just importing and adding PdfViewerComponent to declarations of an Angular 5 module leads to an error when compiling with Angular CLI 1.5 with --aot:

ERROR in TypeError: Cannot read property 'annotation' of null
    at CompileMetadataResolver.loadDirectiveMetadata (C:\Projects\Cat\turbo\turbo-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:14787:109)
    at C:\Projects\Cat\turbo\turbo-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:15073:54
    at Array.forEach (native)
    at CompileMetadataResolver.loadNgModuleDirectiveAndPipeMetadata (C:\Projects\Cat\turbo\turbo-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:15072:41)
    at C:\Projects\Cat\turbo\turbo-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:29416:69
    at Array.forEach (native)
    at C:\Projects\Cat\turbo\turbo-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:29415:35
    at Array.forEach (native)
    at AotCompiler.loadFilesAsync (C:\Projects\Cat\turbo\turbo-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:29414:15)
    at C:\Projects\Cat\turbo\turbo-ui\node_modules\@angular\compiler-cli\src\transformers\program.js:145:35
    at process._tickCallback (internal/process/next_tick.js:109:7)

Tested with 1.1.1 and 2.0.3.
Also there’s an issue in Angular CLI repo.

And when you just import the PdfViewerComponent and don’t add it to declarations, you get this error.

When I remove the import completely, the project gets compiled and works just fine.

1 possible answer(s) on “ng2-pdf-viewer breaks the AOT build with Angular CLI 1.5.0

  1. That was fast! Thanks @VadimDez, it works now in 3.0.0!
    BTW if anyone else stumbles upon this and has a problem like mine, you now need to import PdfViewerModule (not the PdfViewerComponent) and add it to the imports array of your Angular module.