Skip to content

angular 10 library publish error “Trying to publish a package that has been compiled by Ivy” #37973

Closed

Description

@Sikatrih

🐞 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

Activity

  1. petebacondarwin commented on Jul 8, 2020

    @petebacondarwin
    Contributor

    When you are preparing a library for publishing to npm you should use ng build --prod which will ensure it is built in ViewEngine mode, rather than Ivy.

    This is working as expected.

  2. Sikatrih commented on Jul 8, 2020

    @Sikatrih
    Author

    My library is private and needs to be compiled with Ivy.

    According to this table https://gist.github.com/LayZeeDK/61caba93df1ec1a0788c94a973c8dfac
    angular 10 should have ability to build library with Ivy. Or this table is not correct?

    The same discussion was in this issue ng-packagr/ng-packagr#1467

  3. petebacondarwin commented on Jul 8, 2020

    @petebacondarwin
    Contributor

    That table is not correct. Libraries that are published to npm must be built using ViewEngine.

  4. toxity commented on Jul 9, 2020

    @toxity

    @petebacondarwin am I right that the main reason for that is backward compatibility? If so why it is limited for private projects as well. I was hoping that in Angular 10 I will be able to build both internal library and internal project on Ivy while they are both on Angular 10.

  5. petebacondarwin commented on Jul 9, 2020

    @petebacondarwin
    Contributor

    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.

  6. petebacondarwin commented on Jul 9, 2020

    @petebacondarwin
    Contributor

    That being said, if you are in control of your private libraries and will recompile them whenever you update your version of Angular framework, there is no reason why you could not share them internally in ivy compiled form. But then I would not expect you to be publishing them to npm, which is what this check is designed to prevent.

  7. toxity commented on Jul 9, 2020

    @toxity

    The reason why I see this error is that I'm using npm publish with custom URL via --registry param. Is it intentionally blocked too? Maybe I should use some other way or publishing to the private registry?

  8. petebacondarwin commented on Jul 9, 2020

    @petebacondarwin
    Contributor

    In that case the simple workaround is to remove the prepublishOnly property from the library's package.json before publishing.

  9. angular-automatic-lock-bot commented on Aug 20, 2020

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  10. locked and limited conversation to collaborators on Aug 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions