Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular 9 library publish error "Trying to publish a package that has been compiled by Ivy"

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

like image 578
Aniruddha Das Avatar asked Feb 14 '20 21:02

Aniruddha Das


3 Answers

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
like image 96
Aniruddha Das Avatar answered Nov 20 '22 10:11

Aniruddha Das


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;

enter image description here

I've tried it after updating my Angular library to Angular version 9 and this one small change worked like a charm.

like image 19
codeepic Avatar answered Nov 20 '22 10:11

codeepic


Fix for Angular 12+ missing component style issue

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

like image 10
Francesco Borzi Avatar answered Nov 20 '22 09:11

Francesco Borzi