🚨 Step-by-Step Guide to Upgrading to Angular 18 without Zone

Posted by


Angular 18 has been released with a major feature upgrade that is causing quite a bit of buzz in the developer community – zoneless upgrade! This new feature promises faster performance and better memory management by removing the need for Zone.js, the library that has been at the core of Angular’s change detection mechanism since its inception. In this tutorial, we will walk through the steps required to upgrade an existing Angular application to Angular 18 with the zoneless upgrade.

Step 1: Update Angular CLI
The first step in upgrading to Angular 18 is to update your Angular CLI to the latest version. You can do this by running the following command in your terminal:

npm install -g @angular/cli@latest

Step 2: Update Angular dependencies
Next, you will need to update the Angular dependencies in your project’s package.json file. Open the file and update the @angular/core, @angular/common, and @angular/compiler-cli dependencies to version 18.0.0:

"dependencies": {
  ...
  "@angular/core": "^18.0.0",
  "@angular/common": "^18.0.0",
  "@angular/compiler-cli": "^18.0.0",
  ...
}

Then, run the following command in your terminal to install the updated dependencies:

npm install

Step 3: Remove Zone.js
The next step is to remove Zone.js from your project, as it is no longer needed with the zoneless upgrade. You can do this by running the following command:

npm uninstall zone.js

Step 4: Update main.ts file
With Zone.js removed, you will need to make some changes to your main.ts file to enable the zoneless upgrade. First, import the noopZone from @angular/core and use it to create a new NgZone instance without any zone:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { enableProdMode, ɵɵdefineInjector, Injectable, ɵsetClassMetadata } from '@angular/core';
import { ɵɵdefineInjectable, InjectableDef } from '@angular/core';
import { ɵɵinject, ɵɵcore } from '@angular/core';
import { ɵɵdefineInjectable, ɵsetClassMetadata, ɵɵdirectiveInject, ɵɵinject, ɵɵprovide, ɵɵdefineComponent, ɵɵtext } from '@angular/core';

import {noopZone} from '@angular/core';

platformBrowserDynamic()
  .bootstrapModule(AppModule, {
    ngZone: noopZone
  })
  .catch(err => console.error(err));

Step 5: Update zoneless configuration
Finally, you will need to update your project’s configuration file (angular.json) to enable the zoneless upgrade. Add the following configuration to the build section of your project:

"architect": {
  "build": {
    "configurations": {
      "production": {
        "zoneLess": true
      }
    }
  }
}

With these steps completed, your Angular application should now be upgraded to Angular 18 with the zoneless upgrade. Enjoy the improved performance and memory management that this new feature provides!

0 0 votes
Article Rating

Leave a Reply

40 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@AngularUniversity
17 days ago

Enjoy the new Angular 18 Zoneless support 😉One of the most convenient ways of writing zoneless applications is by using Signals. If you want to learn them, check out my ongoing Modern Angular With Signals Course – https://angular-university.io/course/angular-signals-course

@bones_twisting_sorrow4750
17 days ago

great rundown as always

@csayantan
17 days ago

it has a conflict with provideClientHydration() — why?

@vasanthy2k7
17 days ago

I am still using angular 8. 😢

@EtoBARAKUDAvasa
17 days ago

whan I migrate to provideExperimentalZonelessChangeDetection() my tests still want zone.js in angular block "test" in "polyfills": [here…]
I migrate from karma to web-test-runner but still cant run test without zone.js correct. And I check my tests – they doesnt use zone.js

@valeriyaleksandrovich2707
17 days ago

How to difficult to listen you

@big_time_banana
17 days ago

Thanks for the helpful and easy-to-follow video! When I followed your instructions to refactor my app to zoneless, I am getting a ReferenceError: Zone is not defined. Any tips on how to resolve that?

@gauravsahu3828
17 days ago

Is it necessary that if object defined in signalstate will only have deepsignal property.. can we achieve that in component? Without using signalState .?

@codeme8016
17 days ago

Great video. Thanks a lot!

@drax432
17 days ago

Thanks! The only thing i don't like about signal, is that updating its value, involve this.intervalCounter.update(counter=>counter + 1)….instead of the concise this.intervalCounter++. Hopefully future angular will have a shortcut syntax for update of signal.

@josuefreitas2864
17 days ago

So, now I need to know how and when I have to update the page content manually? This seems like a step backwards, from my point of view it's a very expensive change, performance for me has never been a problem in my Angular applications…

@Brendan2Alexander
17 days ago

So I am combing thru a few apps to prepare to go zoneless. All going well…but I am stumped as to what to do with my reactive forms. Will they continue to work? (haha I will soon find out eh?!)

@ErnaSolbergXXX
17 days ago

angular feels like its made by dirty fixes to fix other dirty fixes.

@MonaCodeLisa
17 days ago

you are quick, cool video thank you for sharing 🙂
I still need some time to wrap my mind around some things

@_Afsus
17 days ago

What's the importance of it?

@sudharsanamtk
17 days ago

Still a simple hello world is 500kb

@SkyDeveloper-gy6hd
17 days ago

The Angular 18 Zoneless Change Detection isn't working with AngularFire v18, it produces error when you try to run your App (ReferenceError: Zone is not defined) and causes the App not to run at all… Any fix for that?

@tekforge
17 days ago

Thanks for sharing! I was so excited about the new release that I produced a video about it as well: https://youtu.be/1EAqguJY_kc

@AghileshT
17 days ago

@AngularUniversity Thanks for switching to the VS Code dark theme 🤝, which I commented on Angular Signals video.

@madeOfClay99
17 days ago

Vasco, what are your thoughts on the current Angular Material v18? I personally think that the colors, in some components, such as buttons are messed up, the default themes have applied a very strange use of colors, or should I say, have applied colorless colors

40
0
Would love your thoughts, please comment.x
()
x