Skip to content
Latchkey

Angular "ng build" Budget Exceeded - Fix bundle Size Errors in CI

Angular CLI enforces bundle-size budgets defined in angular.json. When the production build exceeds an error-level budget, ng build fails - by design, to stop bundle bloat from shipping. The fix is to shrink the bundle or, deliberately, raise the budget.

What this error means

ng build (production) fails with Error: bundle initial exceeded maximum budget. Budget 500.00 kB was not met by 120.00 kB with a total of 620.00 kB. It is deterministic and reproduces on every run until the bundle or budget changes.

ng build output
✖ Error: bundle initial exceeded maximum budget.
Budget 500.00 kB was not met by 120.00 kB with a total of 620.00 kB.

✖ Failed to compile.

Common causes

Bundle grew past the error budget

A new dependency, an eagerly imported heavy library, or non-lazy routes pushed the initial bundle over the error threshold in angular.json budgets.

Budget set tighter than the app needs

The configured budget may be unrealistically low for the application, so a legitimate addition trips it.

How to fix it

Shrink the bundle (preferred)

  1. Lazy-load feature routes with loadComponent/loadChildren so they leave the initial bundle.
  2. Import only what you use from large libraries; drop eager imports of heavy modules.
  3. Analyze the bundle (ng build --stats-json + a visualizer) to find the biggest contributors.

Adjust the budget deliberately

If the growth is justified, raise the threshold in angular.json rather than silencing the check.

angular.json
// angular.json -> architect.build.options.budgets
{
  "type": "initial",
  "maximumWarning": "600kb",
  "maximumError": "750kb"
}

How to prevent it

  • Lazy-load routes so the initial bundle stays lean.
  • Keep an initial budget with both warning and error thresholds.
  • Track bundle size in CI so regressions are visible before they fail the build.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →