angular 10 library publish error “Trying to publish a package that has been compiled by Ivy”
See original GitHub issue🐞 bug report
Affected Package
The issue is caused by package @angular-devkit/build-angular:browser
Is this a regression?
No. In version 9 it is expected behavior. But suppose it should not happen in angular V10
Description
I have created project and generate library with angular 10. But I can’t set enableIvy to “true” build and publish my package. It throw error:
my-lib@0.0.1 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
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.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-lib@0.0.1 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
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-lib@0.0.1 prepublishOnly script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in: npm ERR! /home/aa/.npm/_logs/2020-07-08T13_03_35_422Z-debug.log
🔬 Minimal Reproduction
repository with issue: https://github.com/Sikatrih/ng-cli-lib-ivy-issue
🌍 Your Environment
**Angular Version:**
Angular CLI: 10.0.1
Node: 12.16.2
OS: linux x64
Angular: 10.0.2
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.1000.1
@angular-devkit/build-angular 0.1000.1
@angular-devkit/build-ng-packagr 0.1000.1
@angular-devkit/build-optimizer 0.1000.1
@angular-devkit/build-webpack 0.1000.1
@angular-devkit/core 10.0.1
@angular-devkit/schematics 10.0.1
@angular/cli 10.0.1
@ngtools/webpack 10.0.1
@schematics/angular 10.0.1
@schematics/update 0.1000.1
ng-packagr 10.0.0
rxjs 6.5.5
typescript 3.9.6
webpack 4.43.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
The reason is actually forward compatibility. If we allow ivy compiled libraries to be published right now, then we lock ourselves into a very specific use of the ivy instruction set and data structures. This would affect us from being able to make implementation changes that would fix bugs, improvement performance, reduce code size etc. By keeping the ivy internals private we can be more agile going forward.
The current way to achieve this is by requiring ViewEngine compiled code (since this leaves the decorator information in place), which ngcc is able to convert to ivy code at library installation/ application build time. Going forward we are looking into a partially compiled library format that will have the best of both worlds: not requiring a lengthy ngcc build step, but also not exposing the internals of the ivy runtime.
In that case the simple workaround is to remove the
prepublishOnly
property from the library’spackage.json
before publishing.