Quickly Upgrade Your Angular App to the Latest Version 18

Abhinav Akhil
4 min readJul 13, 2024

--

Upgrading your Angular application to the latest version can seem like a daunting task, but with the right steps and understanding, you can quickly and efficiently transition your app to Angular 18. This guide will walk you through the process, ensuring that your application benefits from the latest features, performance improvements, and security updates.

Why Upgrade to Angular 18?

Angular 18 brings a host of new features and improvements, including:

  • Enhanced Performance: Faster load times and better runtime performance.
  • New Features: Introduction of new components and APIs.
  • Improved Developer Experience: Enhanced debugging tools and error messages.
  • Security Updates: Patches for known vulnerabilities and improved security practices.
  • Better Compatibility: Improved support for modern web standards and third-party libraries.

Prerequisites

Before you start the upgrade process, ensure you have the following:

  • Node.js: Make sure you have the latest stable version installed.
  • Angular CLI: Update your Angular CLI to the latest version.
  • Backup: Always backup your project before starting the upgrade process.

For this article, I will be upgrading my Angular 16/17 app to Angular 18. For guidance on your own upgrade, refer to the Angular Update Guide at (https://angular.dev/update-guide). This tool will help you check your current version and the version you want to update to, ensuring you address any issues that arise.

Step-by-Step Upgrade Guide

  1. First we will visit the Angular Update Guide and select the Angular version you want to update from. In this example, I am updating from Angular v17 to the latest v18.

Additionally, select the application complexity & you can also specify the dependencies you use. For example, I use:

  • Angular Material
  • Windows

and click on “Show me how to update” button.

2. Ensure you are using a supported version of Node.js before upgrading your application. Angular v18 supports Node.js versions: v18.19.0 and newer.

3. Navigate to your application’s project directory and execute `ng update @angular/core@18 @angular/cli@18 — force` to update to Angular v18.

4. Next, update Angular Material by running `ng update @angular/material@18`.

5. Depending on your project setup, review these changes and follow the instructions in the Angular Update Guide to complete the update process.

6. Handle Third-Party Dependencies:

Third-party dependencies might need updates to be compatible with Angular 18. Check for any outdated packages:

Run the following command to see outdated packages:

npm outdated

Update the outdated packages:

npm update

Some packages might require manual intervention if they have major updates or breaking changes. Check the documentation for each package for specific update instructions.

7. Update TypeScript Version

Angular 18 may require a specific TypeScript version. Ensure you have the correct TypeScript version installed:

Check the Angular documentation for the required TypeScript version.

Update TypeScript to the required version:

npm install typescript@<required_version>

Replace <required_version> with the version specified in the Angular documentation.

Once completed, your application will be upgraded.

Next, we will address some common errors you may encounter.

Error: ‘Hue “500” does not exist in palette. Available hues are: 0, 10, 20, 25, 30, 35, 40, 50, 60, 70, 80, 90, 95, 98, 99, 100, secondary, neutral, neutral-variant, error’

Solution: To fix this issue, please update the following:

mat.define-palette to mat.m2-define-palette
mat.define-typography-config to mat.m2-define-typography-config
mat.define-light-theme to mat.m2-define-light-theme
mat.define-dark-theme to mat.m2-define-dark-theme
mat.red-palette to mat.$m2-red-palette

You can check all the Breaking Angular Material changes from here https://github.com/angular/components/releases/tag/18.0.0.

Read more about this issue here:

  1. https://stackoverflow.com/questions/78538692/angular-material-18-hue-500-does-not-exist-in-palette
  2. https://github.com/angular/components/issues/29119
  3. https://github.com/angular/components/issues/29117

Error: The Angular Compiler requires TypeScript >=5.4.0 and <5.5.2 but 5.5.2 was found instead

Solution: To fix this issue, run the following command which will ensure the correct version of typescript is available

npm install typescript@">=3.4.0 and <3.5.0" --save-dev

Read more about this issue here:

https://stackoverflow.com/questions/57216110/the-angular-compiler-requires-typescript-3-4-0-and-3-5-0-but-3-5-3-was-found

Tips for a Smooth Upgrade

After completing the updates, thoroughly test your application to ensure everything is working correctly:

  • Read the Documentation: Thoroughly read the Angular documentation and update guide.
  • Backup Your Project: Always create a backup before starting the upgrade process.
  • Test Frequently: Regularly run tests to catch issues early. Run unit tests and e2e tests.
  • Stay Informed: Follow the Angular blog and community forums for the latest updates and tips.

Conclusion

Upgrading to Angular 18 ensures your application stays up-to-date with the latest features, performance improvements, and security patches. By following this step-by-step guide, you can quickly and efficiently upgrade your Angular app, taking advantage of all the benefits Angular 18 has to offer.

For more detailed information, check the official Angular Update Guide.

By keeping your application updated, you not only improve its performance and security but also ensure a better experience for your users. Happy coding!

--

--

Abhinav Akhil
Abhinav Akhil

Written by Abhinav Akhil

I create software, that tell stories.

No responses yet