I'm trying to make an angular library with secondary entry point for every module.
I have three modules: A, B and C.
A is standalone, but B depends on C, meaning I have import
to get C.module.ts
in B.module.ts
.
I followed this article, so I have a package.json
, index.ts
and public_api.ts
files in every module.
When I try to build the lib, I get the following error:
------------------------------------------------------------------------------
Building entry point '@org/library-name/src/lib/A'
------------------------------------------------------------------------------
Compiling TypeScript sources through ngc
Bundling to FESM2015
Bundling to UMD
Minifying UMD bundle
Writing package metadata
Built @org/library-name/src/lib/A
------------------------------------------------------------------------------
Building entry point '@org/library-name/src/lib/B'
------------------------------------------------------------------------------
Compiling TypeScript sources through ngc
ERROR: Unable to write a reference to CComponent in /.../projects/library-name/src/lib/C/C.component.ts from /.../projects/library-name/src/lib/C/C.module.ts
Any idea on how to make it work? Thanks in advance.
I can tell you how I workarounded this problem.
The problem here is to understand how
ng-packagr
builds our libraries depending the entry-points/folder structure.In my particular situation I had the following structure:
The output is 2 chunks, right?
my-lib/common
andmy-lib/common/big-chunk
It happens that the secondary entry points are built BEFORE the main one, so having a shared logic, I will need to put it (and export it) on the secondary entry-point
my-lib/common/big-chunk
and use it on the main onemy-lib/common
.If you find yourself with the need of sharing logic, consider to create a
shared
entry point.I found very tricky to use and implement secondary entry points and some refactors might be needed to make them work and take the whole benefit they can bring, but overall I think it totally worth it :)