Angular 库 PROD 构建抛出异常

Angular library PROD build throws exception

我有一个 Angular 9 库,我想将其推送到注册表。

当我 运行 ng build <my-lib> 时,它构建正确,但它抱怨 Ivy:

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

因此无法推送:

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.

当我 运行 ng build <my-lib> --prod 时,它抛出关于 [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">")

我验证了并且我的所有模块都导入了 CommonModule

为什么在没有 --prod 的情况下可以正常构建,但是当我想为 --prod 构建它时它会抱怨?

您正在尝试使用您的应用程序中不存在的指令 [hidden]。

在您的模块中注册该指令或使用 *ngIf[ngClass],我认为这是您希望 "hidden" 执行的操作