Angular 9 Library Build Error: Failed to find exported name of node

Viewed 1657

In my Angular 9 (Everything up to date) I use several own libraries. The libraries are included in the tsconfig.json using the "paths" property and then used it in the application.

I create a new library which using a lot of the CdkPortal from the Angular Cdk Library, I get the following error messages while compiling the root Application which imports the Library. Before that I compile the library itself and there is no build error:

    Compiling cap-gui-components : module as esm5
Error: Error on worker #1: Error: Failed to find exported name of node (CapGuiSettingsDialogContainerComponent 

All components which are loaded dynamically with the Cdk will generate this error message. Theoretically, these components do not need to be exported in the index.ts file because they are only used in the library itself. If I export them, I do not get the error message.

Full Error Message:

ompiling cap-gui-components : module as esm5
Error: Error on worker #1: Error: Failed to find exported name of node (CapGuiSettingsDialogContainerComponent = /** @class */ (function () {
    // ************************************************************************************************
    /** Constructor */
    ...code...

in 'C:/Users/Arbeit/dev/CaptureWebApplications/dist/cap-gui-components/fesm5/cap-gui-components.js'.
    at Object.findExportedNameOfNode (C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\@angular\compiler-cli\src\ngtsc\imports\src\find_export.js:35:19)
    at LogicalProjectStrategy.emit (C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\@angular\compiler-cli\src\ngtsc\imports\src\emitter.js:228:38)
    at ReferenceEmitter.emit (C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\@angular\compiler-cli\src\ngtsc\imports\src\emitter.js:71:44)
    at Object.toR3Reference (C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\util.js:192:31)
    at NgModuleDecoratorHandler._toR3Reference (C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\ng_module.js:417:31)
    at C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\ng_module.js:196:83
    at Array.map (<anonymous>)
    at NgModuleDecoratorHandler.analyze (C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\ng_module.js:196:48)
    at NgccTraitCompiler.TraitCompiler.analyzeTrait (C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\@angular\compiler-cli\src\ngtsc\transform\src\compilation.js:345:40)
    at analyze (C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\@angular\compiler-cli\src\ngtsc\transform\src\compilation.js:297:58)
    at ClusterMaster.onWorkerMessage (C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:168:27)
    at C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:52:95
    at ClusterMaster.<anonymous> (C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:248:57)
    at step (C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\tslib\tslib.js:139:27)
    at Object.next (C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\tslib\tslib.js:120:57)
    at C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\tslib\tslib.js:113:75
    at new Promise (<anonymous>)
    at Object.__awaiter (C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\tslib\tslib.js:109:16)
    at EventEmitter.<anonymous> (C:\Users\Arbeit\dev\CaptureWebApplications\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:242:32)
    at EventEmitter.emit (events.js:311:20)
An unhandled exception occurred: NGCC failed.
See "C:\Users\Arbeit\AppData\Local\Temp\ng-dpI2TJ\angular-errors.log" for further details.

Why do I need to export these Components? Is there a other way to build that library without error and without export these components?

4 Answers

Not even an hour later I found the solution. I need to enable ivy in the tsconfig.lib.prod.ts. Now the library compiles with Ivy and that isnt recommended yet but it all works fine.

For the record, I had this cryptic error on a library (we made ourselves), on a class, that compile both fine, and the demo / test of the library was working.
The error appeared after I updated the dependencies of the application using this library, among others, in the ngcc compilation phase after the npm i one.

I finally understood that it was because I provided the module where this class (a ngLet directive) was declared in another module of the same library, but it wasn't needed.
I still don't understand why I got this error, but I am glad it is gone…

In the issue I was having, I was compiling with enableIvy: false and was missing an export of a module. The library compiled fine, but when compiling on the consumer side, it gave this error. Exporting the missing module and then installing on the consumer side fixed the issue.

So, I was facing the exact same issue. It turns out that the compiler was not finding the appropriate type declarations for this library. My fix was to add the library to the typeRoots array in the root tsconfig.

"typeRoots": [
  "typings",
  "node_modules/@types/",
  "libraryname",
],
Related