DEV Community

John Peters
John Peters

Posted on • Edited on

It is not recommended to publish Ivy libraries to NPM repositories

Okay we get it, all the hype to get to Angular 9 was to get to the new Ivy compiler and renderer. The whole upgrade a veritable total mess with goofy NPM dependency messages and tons of lost time just upgrading.

Meanwhile
We start our merry way trying to create a reusable library only to see this message each time we compile.

The work around is simple:

Before publishing a library to NPM, 
build it using the --prod flag which will
use the older compiler and runtime 
known as View Engine instead of Ivy.
Enter fullscreen mode Exit fullscreen mode

Umm, ok Google, please tell me again the benefits of Ivy? While you're at it, why can't we use Ivy for libraries?

Root Cause

After looking into this a bit, it turns out Angular doesn't want Ivy packages in NPM. I have no idea why. However, this error message is only seen when we type in

ng build
//instead of 
ng build --prod
Enter fullscreen mode Exit fullscreen mode

One last tip, Angular 9 libraries are not compatible with prior versions of Angular. Don't even think of trying it.

Top comments (2)

Collapse
 
negue profile image
negue

I think its because the ivy-built library wouldn't be able to be used with angular 8 (view-engine) projects, they probably want library maintainers to be compatible with older versions.

But once you published your library, and use in in your Ivy app, you'll still receive the benefits, cause its all optimized in the end.

Collapse
 
jwp profile image
John Peters • Edited

Let me try to understand. I think you are saying that for all of the developers out there still in Angular 8, these parts would not mesh. It's an environment issue with the development environment.

In other languages like C# one cannot import libraries higher than the current project, but the warnings are clear, it just cannot be done. Maybe the whole import system doesn't take a release into account?

One thing is clear to me, the NPM Module environment is a mess for sure.