I migrated my angular 8.x.x
project to angular 9.x.x
and when I try to publish my library, it fails with below error
npm ERR! @candiman/[email protected] 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
is there anything changed in the angular 9
UPDATE ANGULAR 12
using the --configuration production
option while building the library fixed my issue
ng build --configuration production
Original answer:
using --prod
option while building the library fixed my issue
ng build yourLibraryName --prod
According to official Angular docs https://angular.io/guide/ivy#opting-out-of-ivy-in-version-9
it is better to opt out from Ivy compiler to use the older View Engine when building and publishing your library by adding this line:
enableIvy: false
to angularCompilerOptions in tsconfig.json file at the root of your library as can be seen below;
I've tried it after updating my Angular library to Angular version 9 and this one small change worked like a charm.
On Angular 12, while using:
ng build --configuration production
indeed solved the original issue for me, it also introduced a new one: the styles of my library component where completely missing.
I've solved this other problem by replacing:
"angularCompilerOptions": {
"enableIvy": false
}
with:
"angularCompilerOptions": {
"compilationMode": "partial"
}
in projects/my-library/tsconfig.lib.prod.json
Source: https://angular.io/guide/creating-libraries#building-libraries-with-ivy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With