-1

We have a library project that lives in an nx project that we publish to npmjs. It's a collection of components derived from @angular/material. The library is published to npmjs @vdlx/vdl-angular.

Our build uses ng-packagr to build each of the components successively based on their dependencies.

When installed from npm into either clean angular-cli or nx project, the ng build command works fine but the ng build --aot fails with errors.

Within the library nx project building the apps with aot works fine, likely because it gets the components from the source (vs node_modules or the project /dist folder).

ERROR in ./src/app/app.module.ngfactory.js
Module not found: Error: Can't resolve 'badge' in '/Users/dale.manthei/Downloads/angular-hrvy5y/src/app'

Here is a simple recreate for the problem: https://stackblitz.com/edit/angular-hrvy5y?file=src%2Fapp%2Fapp.module.ts.

It works in the stackblitz for sure. Installing the project locally and running the ng build --aot fails.

I suspect there is something missing from our library that the angular-cli project expects to be there. So far I have been trying to work with the consuming application but no joy there.

Suggestions welcome.

1 Answers1

0

It turns out the problem lies in the published library. When I posted the question I couldn't tell if the issue was with the consuming application or the component library. Turns out it was the latter.

To track it down we manually generated the ngfactory files to find where the name was the simple badge.

Using that I was able to go back to the component ng-packagr configuration in the library nx project. Changing the name in the component package.json to include the npmj namespace as well as the library namespace does the trick.

With this, we're now building a component library using ng-packagr where components import other components much like this issue in https://github.com/nrwl/nx/issues/602.