Migrate an Angular App from NgModule Bootstrapping to bootstrapApplication
Replace Angular NgModule bootstrapping with bootstrapApplication and standalone components. Includes main.ts example, route configuration, build checks, and rollback steps.
08 Aug 2025, 18:14 UTC

Problem and takeaway
Angular applications created with older CLI versions bootstrap through an NgModule: platformBrowserDynamic().bootstrapModule(AppModule). That model forces you to declare components, directives, and pipes in modules even when you use standalone APIs. The practical takeaway is that you can switch to bootstrapApplication and delete the root module, but you must move every provider into the application config and verify the production build before deploying.
Desired outcome
A running Angular app that boots with bootstrapApplication, uses a standalone root component, and configures routes and providers without AppModule.
Prerequisites
- Angular version 14 or later; standalone component APIs were introduced in v14.
- Angular CLI installed in the project.
- An existing app with
src/app/app.module.tsandsrc/main.tsusingbootstrapModule. - A Git repository or recent backup, because this procedure changes source files.
Procedure
1. Confirm the Angular version
Run this in the project root. No elevated permissions are required.
ng version
Expected check: the Angular CLI version is 14 or higher. If it is lower, standalone bootstrapping is not supported and you must upgrade Angular first.
2. Make the root component standalone
Open src/app/app.component.ts and add standalone: true to the component decorator:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
standalone: true,
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'my-app';
}
standalone means the component is not declared in any NgModule. Remove AppComponent from the declarations array of AppModule if it is listed there.
3. Replace bootstrapping in main.ts
Open src/main.ts. Replace the NgModule bootstrap call with bootstrapApplication.
Before:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch((err) => console.error(err));
After:
import { bootstrapApplication } from '@angular/platform-browser';
import { provideRouter } from '@angular/router';
import { provideHttpClient } from '@angular/common/http';
import { importProvidersFrom } from '@angular/core';
import { AppComponent } from './app/app.component';
import { routes } from './app/app.routes';
import { LegacyModule } from './legacy/legacy.module';
bootstrapApplication(AppComponent, {
providers: [
provideRouter(routes),
provideHttpClient(),
importProvidersFrom(LegacyModule)
]
})
.catch((err) => console.error(err));
bootstrapApplication boots a standalone component directly. provideRouter registers the route configuration. provideHttpClient registers HTTP client services. importProvidersFrom bridges providers from a legacy NgModule into the standalone injection context; use it only for libraries that still ship as NgModules.
4. Configure routes
Create src/app/app.routes.ts:
import { Routes } from '@angular/router';
import { HomeComponent } from './home/home.component';
export const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'about', loadComponent: () => import('./about/about.component').then((m) => m.AboutComponent) }
];
loadComponent is the standalone route syntax for lazy loading. Verify that the imported file exports a standalone component; otherwise the router may fail to resolve the route.
5. Remove the root module
Delete src/app/app.module.ts or remove its contents. Confirm no remaining file imports AppModule. If you keep the file for reference, do not import it in main.ts.
6. Add legacy module providers if needed
If a third-party library still requires an NgModule, add it through importProvidersFrom as shown above. Not all legacy libraries work this way; test the build after adding each one.
Expected checks
- Run the production build in the project root:
ng build --configuration production
Expected result: the build completes without template compiler errors about missing declarations or unknown elements.
- Start the development server:
ng serve
Open the application URL and confirm the root component renders and navigation between standalone routes works.
- Run the test suite:
ng test
Expected result: tests pass and cover rendering and routing behavior.
- Inspect
src/main.tsto confirm it importsbootstrapApplicationfrom@angular/platform-browserandprovideRouterfrom@angular/router.Rollback
This operation changes source files. If the migration fails, revert the changed files with Git:
git checkout -- src/main.ts src/app/app.component.ts src/app/app.module.tsThen restore the original
bootstrapModulecall inmain.ts, redeclare components inAppModule, and runng build --configuration productionto confirm the app builds as before.Limitations and verification notes
- Do not call
bootstrapModuleandbootstrapApplicationin the same application; select one bootstrapping model. - Standalone route lazy loading uses
loadComponent; verify route configs match the target symbol. - Pre-v14 third-party libraries may still require NgModule imports and can need wrapper modules or
importProvidersFrom. - Exact API stability depends on the installed Angular minor release; check the release notes for your target version.
- This draft requires human verification against your installed Angular version before production use.
Practical way to check the result: run
ng build --configuration production, then load the app withng serveand click through each route. If the build succeeds and navigation works, the standalone bootstrapping migration is functioning. - Do not call