Search code examples
angularng-packagr

Angular library PROD build throws exception


I have an Angular 9 library which I would like to push to registry.

When I run ng build <my-lib>, it builds correctly, but it complains about Ivy:

******************************************************************************
It is not recommended to publish Ivy libraries to NPM repositories.
Read more here: https://v9.angular.io/guide/ivy#maintaining-library-compatibility
******************************************************************************

and it's impossible to push due to this:

ERROR: Trying to publish a package that has been compiled by Ivy. This is not allowed.
Please delete and rebuild the package, without compiling with Ivy, before attempting to publish.

When I run ng build <my-lib> --prod, it throws an error about [hidden]:

[error] Error: Can't bind to 'hidden' since it isn't a known property of 'ng-content'.
1. If 'hidden' is an Angular directive, then add 'CommonModule' to the '@NgModule.imports' of this component.
2. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("][hidden] = "!active">")

I verified and all my modules import CommonModule.

Why is it building fine without --prod, but when I want to build it for --prod it complains?


Solution

  • You are trying to use directive [hidden] which not exist in your app.

    Register that directive in your module or use *ngIf or [ngClass] which i assume is what you expected from "hidden" to do