How to upgrade badly outdated angular project?

3.3k views Asked by At

We are upgrading large scale angular app from 6 to 17. Like everybody else I have also been following Angular Upgrade Guide: but that always talks about upgrading one version at a time.

Our app has nearly 50 third party libraries. So upgrading libraries is the major work compared to upgrading the angular version itself.

As an architect I do not see any point in travelling from v6 to v17, step by step.

In 2023 why any one would write the code of intermediate versions (of angular and used 3rd party libraries) just to discard them?

IMHO there has to be a better guidance on how to upgrade badly outdated Angular projects, but cound't find authoritative answer on the topic.

Is there any logic on why one should not move to V17 directly? Why it is officially recommended to go step by step?

Any guidance is greatly appreciated, thank you.

4

There are 4 answers

0
Gopinath On BEST ANSWER

If the angular app is badly outdated, then it is very difficult to upgrade it.

This is not a problem with Angular. 'Inability to upgrade easily' is a wellknown problem with almost all of the opensource software utilities. Opensource never comes with the guarantee of extremely long term backward compatibility or upgrading by skipping major versions.


Angular 6 was released in 2018.

Many things have changed since then. Many projects on NPM have got closed down. New projects sprang up. Typescript language had changed considerably in the past 5 years. Nodejs platform went through major updates.

Angular 17 is released in Novemebr 2023.

Jumping from 6 to 17 is a very long jump. Doing it successfully requires the understanding of changes that have happended in the past 5 years not only to Angular, but also to its ecosystem (Typescript, Nodejs, RXJS, Webpack, NPM packages).

If some of the dependencies have become deprecated, then the effort of finding and testing the replacements for the dependencies will also be required.


These are my findings based on my experience of upgrading several Angular projects in the past 8 years:

1. Upgrade from Angular 12 to 17 is easy.

Typescript language, Nodejs and the general NPM dependencies for Angular did not have many breaking updates since late 2021. Angular evolved from version 12 to 17 during this period. Upgrade from Angular 12 to 17 is fairly easy, as the ecosystem had been generally stable in this period. Most of the Angular 12 projects can be directly upgraded to 17 without code changes.

2. Upgrade from Angular 2 to 11 is difficult

Between 2016 and 2021, there was a tremendous change in the ecosystem. COVID19 pandemic also caused problems to many opensource projects. Angular evolved from version 2 to 11 during this period. Upgrading Angular from version 2 to any other version till 11 was very difficult due to the nature of changes in the ecosystem at that time.

3. Very difficult to upgrade from before 12 to 13 or above

Nodejs and Typescript have had numerous updates coinciding with the timeframe of Angular changing from 11 to 12. Upgrading Angular from any version below 12 to a version above 12 is very difficult due to this.


Recommended upgrade approach for Angular 6 to 17 Though the best practice is to do a step-by-step upgrade, one major version at a time, it can be safely avoided in many cases.

Based on my experience and consideration of the timelines of breaking changes, this 4 stage upgrade will be the easiest:

  • Stage 1: Upgrade from Angular version 6 to 9
  • Stage 2: Upgrade from Angular 9 to 11
  • Stage 3: Upgrade from Angular 11 to 12 or 13
  • Stage 4: Upgrade from Angular 12/13 to 17
0
Charles Merriam On

This is a cost function, and you are probably making the correct guess in jumping to the new version.

  • Cost of trying to upgrade version by version has very high costs. There are many versions, which would having you solve transient problems such as upgrading a library for an intermediate version, only to find that the library is completely replaced by your target version.
  • Cost of trying to do a jump upgrade is also high. Odds are that many libraries have changed, some paradigm changes require redesign of code. My years of experience still says do the jump.

That said, you now have a stack of "legacy code". You should follow the usual steps:

  • Make sure to maintain a machine running a working copy of the legacy code at all times. This allows you to add new formal or informal tests when trying to get your current version to run. This does not need to be a version that is using "live" data.
  • Depending on your exact application, you may be able to run a hybrid system. For example, you have a router that runs the old system for generating patient bill PDFs and doing some obscure calculations. You route to the new system for the appointment scheduler. Over time, you route to the new system for everything. This works for some applications and not for others.
  • Really avoid letting every possible new feature people of dreamed about for the last few years be part of the success criteria of your project. Argue that it will be easy to add features once you are stable.
  • Automated formal tests are great, if you have them. Even manual semi-formal tests are great. That is, "I add an appointment, mark it as missed, and see that the patient is billed for a no show. Works in the old and new system.
  • Your PID, or design for the non-project oriented people, should look at the list of libraries linked and which have been abandoned.

You have a project, not an afternoon's effort.

0
Amirhossein Mehrvarzi On

IMO, the Angular Upgrade Guide is suitable for cases where you are a few versions behind the latest. So, It's not a good way for your case.

Unfortunately, there are a lot of (breaking) changes in the codebase and the project structure that you need to apply one by one. The migration process is not simple, and I think that's why the Angular development team couldn't deliver a reliable and straightforward solution to make all the required changes at once.

I suggest the best way which is creating a new project from scratch using the latest Angular version and making the changes one by one. Otherwise, you'll get strange errors, and it will take you so much time to resolve even the simple issues. Here you can prioritize all the steps to speed up the process. You also need to make sure the latest or specific versions of the 3rd party libraries are compatible with the new Angular project and its dependencies (one by one).

0
Nirav Ghodadra On

I understand your concern and the biggest hurdle you'll face when you upgrade angular version one by one is for every versions you have to work and fix the third party library versions.

I would suggest you two approach. I would prefer 1st one though.

  1. Good Approach with more time cost
  • Upgrade angular to new version and then check each library and also update them to the latest version compatible to your current angular version.
  • Run the code and keep updating your code and fix all the errors and the changes occurred due to library changes.
  • Some libraries would also have major changes and you have to do many changes as well.
  • So start with library having minor changes and then go with libraries having major changes (it would be generally ui component library like material or primeNg)
  • There will be lot of work but at the end of the day you'll have you angular and all the libraries updates as well.
  1. Moderate approach with less time cost
  • Upgrade the angular version to latest version and then run the code. Now fix all the errors and libraries version conflict.
  • You'll have to work less in this approach but at the end of the day you'll still have some libraries with older version.
  • I suggest if you are spending time in upgrading your project you should update all the libraries as well.