Ani*_*Das 28 angular-cli angular angular-library angular-cli-v9
我将我的angular 8.x.x
项目迁移到angular 9.x.x
,当我尝试发布我的库时,它失败并显示以下错误
npm 错误!@candiman/website@9.0.0 prepublishOnly:
node --eval "console.error('ERROR: Trying to publish a package that has been compiled by Ivy. This is not allowed.\nPlease delete and rebuild the package, without compiling with Ivy, before attempting to publish.\n')" && exit 1
有什么变化吗 angular 9
Ani*_*Das 50
更新角度 12
--configuration production
在构建库时使用该选项修复了我的问题
ng build --configuration production
Run Code Online (Sandbox Code Playgroud)
原答案:
--prod
在构建库时使用选项修复了我的问题
ng build yourLibraryName --prod
Run Code Online (Sandbox Code Playgroud)
Fra*_*rzi 24
在 Angular 12 上,使用时:
ng build --configuration production
Run Code Online (Sandbox Code Playgroud)
确实为我解决了最初的问题,它还引入了一个新问题:我的库组件的样式完全丢失。
我通过替换解决了另一个问题:
"angularCompilerOptions": {
"enableIvy": false
}
Run Code Online (Sandbox Code Playgroud)
和:
"angularCompilerOptions": {
"compilationMode": "partial"
}
Run Code Online (Sandbox Code Playgroud)
在projects/my-library/tsconfig.lib.prod.json
来源:https://angular.io/guide/creating-libraries#building-libraries-with-ivy
cod*_*pic 16
根据官方 Angular 文档https://angular.io/guide/ivy#opting-out-of-ivy-in-version-9
通过添加以下行,在构建和发布您的库时,最好选择退出 Ivy 编译器以使用较旧的视图引擎:
enableIvy: false
到库根目录下 tsconfig.json 文件中的 angularCompilerOptions ,如下所示;
我在将我的 Angular 库更新到 Angular 版本 9 后尝试过它,这个小小的改变就像一个魅力。
小智 6
在使用ng build --prod
和enableIvy = false
in构建我的库时tsconfig.lib.json
,我将package.json
与Melchia相同的“prepublishOnly”脚本添加到我的工作区中。
publishConfig/registry
原因似乎与在每个库中使用私有存储库有关package.json
,如https://github.com/angular/angular/issues/37973#issuecomment-656136865中所述
当构建用于发布的 Angular 库时,请在库中ng build --prod
使用, 如果使用私有存储库,enableIvy = false
tsconfig.json
npm publish --ignore-scripts
就我而言,上述解决方案均无效。然而,我注意到在package.json
我的库的 dist 文件夹中有一个新添加的脚本(可能是因为这个而添加的):
"scripts": {
"prepublishOnly": "node --eval \"console.error('ERROR: Trying to publish a package that has been compiled by NGCC. This is not allowed.\\nPlease delete and rebuild the package, without compiling with NGCC, before attempting to publish.\\nNote that NGCC may have been run by importing this package into another project that is being built with Ivy enabled.\\n')\" && exit 1"
}
所以在这里要么删除/替换prepublishOnly
脚本,要么使用发布npm publish --ignore-scripts
归档时间: |
|
查看次数: |
13499 次 |
最近记录: |