DEV Community

Aakash Singh
Aakash Singh

Posted on

Angular Library Compatibility: Using Version 14 Libraries in Version 12 or 17 Applications

I've created several Angular libraries using version 14. I'm interested in incorporating them into applications built with Angular versions 12 or 17. However, I'm encountering errors during this process. Could you please clarify the compatibility between these versions and provide guidance on addressing the errors I'm facing?

Top comments (1)

Collapse
 
lalves91 profile image
LAlves91

Greetings!

According to Angular's official documentation, applications must have at least the same version as the library.

Version 14 had some major changes, like Typed Forms. If your library has form related components (which is usually true for multi-components libraries), v12 or v13 apps won't be able to finish the library's partial compilation, since their Angular packages won't have the necessary artifacts.

Now, although the docs say:

The Angular version used to build an application should always be the same or greater than the Angular versions used to build any of its dependent libraries

There are mutiple challenges when you have apps with a greater major version than your libraries. You have to make sure the libraries aren't using any Angular feature that had a breaking change in the app's Angular version.

Things become even more complicated if your library depends on a third-party Angular library. A common example: if one of your libraries use Angular Material v14 and an application is in a greater major version, you gotta take into account the major breaking change that happened in Angular Material v15, which changed most of the CSS classes across the whole codebase. Although there are ways to mitigate some of the breaking changes, it's still something that could break your apps if left unchecked.

There's no easy way to handle this scenario. You need to check the pros and cons of the possible choices:

  • Aligning your libs/apps Angular versions, and gradually updating the whole ecosystem when necessary;
  • Maintaining multiple versions of your libraries targeting different Angular major releases, taking your apps into consideration (when the most outdated app jumps one major, you cut that previous Angular version support from your libraries).

Sorry for the long (and mostly without a final solution) reply hahahahh