---
title: "Migrating from NgModules to Standalone Components in Angular"
description: "Moving an existing Angular app from NgModules to standalone components: the official schematic, bootstrapApplication, providers, lazy loading and pitfalls."
url: https://sanderyaz.com/en/blog/angular-standalone-migration/
author: Sander Yazıcıoğlu
date: 2026-12-02
updated: 2026-12-02
lang: en
tags: ["Angular","Migration","Frontend","TypeScript"]
---

# Migrating from NgModules to Standalone Components in Angular

Standalone components made NgModules, for years one of the hardest concepts for Angular newcomers, optional, and became the default in Angular 19. In a large, older app this migration can look scary, but Angular's official schematic does most of the work. This article walks through it in safe steps.

## What standalone buys you

- **Less boilerplate:** each component lists its dependencies in its own `imports` array; no more tracking which module exports what.
- **Better tree-shaking:** unused components stay out of your bundles.
- **Simpler lazy loading:** routing to a single component no longer requires a module.

```ts
@Component({
  selector: 'app-run-list',
  imports: [DatePipe, RouterLink, RunStatusBadge],
  template: `...`
})
export class RunListComponent {}
```

## Prerequisite: a current version

Before migrating, the app should be on at least Angular 15, ideally the current version. I cover upgrading in the [Angular upgrade guide](/en/blog/angular-upgrade-guide/).

## The official schematic: three steps

```bash
ng generate @angular/core:standalone
```

The schematic asks you to pick a mode, and you are meant to run each mode in order:

1. **Convert all components, directives and pipes to standalone:** adds `imports` to components and updates module declarations.
2. **Remove unnecessary NgModule classes:** deletes modules that no longer do anything.
3. **Bootstrap the application using standalone APIs:** switches from `AppModule` to `bootstrapApplication`.

After each step, build, run the tests and **commit**. If something breaks, you know which step did it.

## The new bootstrap

```ts
bootstrapApplication(AppComponent, {
  providers: [
    provideRouter(routes, withComponentInputBinding()),
    provideHttpClient(withInterceptors([authInterceptor])),
    provideAnimationsAsync()
  ]
});
```

`provide...` functions replace `HttpClientModule`, `RouterModule.forRoot` and friends. If you have class-based interceptors, `withInterceptorsFromDi()` keeps them working while you move to functional interceptors.

## Lazy loading

```ts
export const routes: Routes = [
  { path: 'runs', loadComponent: () => import('./runs/run-list.component').then(m => m.RunListComponent) },
  { path: 'admin', loadChildren: () => import('./admin/admin.routes').then(m => m.ADMIN_ROUTES) }
];
```

Declaring feature-specific services with route-level `providers` replaces the `providers` array of feature modules.

## Pitfalls

- **Shared modules:** if a giant `SharedModule` exports everything, the schematic may add it to components' `imports`. Over time import the pieces you actually use directly, or you lose much of the tree-shaking gain.
- **Third-party libraries:** older libraries may still export NgModules; adding a module to a standalone component's `imports` is fine.
- **Tests:** in `TestBed.configureTestingModule` the component moves from `declarations` to `imports`. The schematic updates most tests, but some need manual fixes.
- **Circular imports:** two components importing each other fail to compile; extract the shared part into its own component.

## Measure

Compare the main bundle size and initial load time before and after. As you break up shared modules, you'll see the bundle shrink.

## Conclusion

The standalone migration is not a rewrite but a modernisation in three safe steps with the official schematic. You end up with more readable components, simpler routes and smaller bundles.

---

About the author: [Sander Yazıcıoğlu](https://sanderyaz.com/en/about/). Sander Yazıcıoğlu is a Senior Full-Stack Developer in Istanbul. At LiveTesting he builds the backend, frontend, realtime systems and Appium automation of a real-device testing platform; before that he built enterprise Angular apps at Testinium and Loadium.
