在使用angular自定义组件库,构建npm包时报错:It is not recommended to publish Ivy libraries to NPM repositories.
ERROR: projects/ngx-zorro/src/lib/alert/alert.component.ts:8:14 - error NG3001: Unsupported private class AlertComponent. This class is visible to consumers via NgxZorroModule -> AlertComponent, but is not exported from the top-level library entrypoint.
Building Angular Package
******************************************************************************
It is not recommended to publish Ivy libraries to NPM repositories.
Read more here: https://v9.angular.io/guide/ivy#maintaining-library-compatibility
******************************************************************************
------------------------------------------------------------------------------
Building entry point 'ngx-zorro'
------------------------------------------------------------------------------
Compiling TypeScript sources through ngc
ERROR: projects/ngx-zorro/src/lib/alert/alert.component.ts:8:14 - error NG3001: Unsupported private class AlertComponent. This class is visible to consumers via NgxZorroModule -> AlertComponent, but is not exported from the top-level library entrypoint.
8 export class AlertComponent implements OnInit {
~~~~~~~~~~~~~~~
An unhandled exception occurred: projects/ngx-zorro/src/lib/alert/alert.component.ts:8:14 - error NG3001: Unsupported private class AlertComponent. This class is visible to consumers via NgxZorroModule -> AlertComponent, but is not exported from the top-level library entrypoint.
8 export class AlertComponent implements OnInit {
~~~~~~~~~~~~~~~
解决:
由于ng9之后默认使用ivy引擎。官方并不建议把 Ivy 格式的库发布到 NPM 仓库。
因此在发布到 NPM 之前,我们使用–prod标志构建它,此标志会使用老的编译器和运行时,也就是视图引擎(View Engine),以代替 Ivy。
ng build ngx-zorro --prod
另外,打包前修改package.json中的项目信息,每次更新npm包需修改version,版本相同提交不上去,可以手动修改,也可命令修改,如下:npm version prepatch
。
更多操作:
# 版本号从 1.2.3 变成 1.2.4-0,就是 1.2.4 版本的第一个预发布版本。
npm version prepatch
# 版本号从 1.2.4-0 变成 1.3.0-0,就是 1.3.0 版本的第一个预发布版本。
npm version preminor
# 版本号从 1.2.3 变成 2.0.0-0,就是 2.0.0 版本的第一个预发布版本。
npm version premajor
# 版本号从 2.0.0-0 变成 2.0.0-1,就是使预发布版本号加一。
npm version prerelease