Angular "bundle initial exceeded maximum budget" in CI
ng build compared the size of your initial bundle against the budgets entry in angular.json and it crossed the maximumError threshold. The build succeeds locally on warnings but the CI build fails once the size passes the error limit.
What this error means
ng build --configuration production fails with "Error: bundle initial exceeded maximum budget. Budget X was not met by Y" and exits non-zero, breaking the CI job even though compilation itself was clean.
Error: bundle initial exceeded maximum budget. Budget 500.00 kB was not met by 143.21 kB with a total of 643.21 kB.Common causes
A new dependency pushed the initial bundle past maximumError
Importing a large library into an eagerly loaded module grows the initial bundle beyond the maximumError you set in the budgets array in angular.json.
Eagerly importing code that should be lazy loaded
A feature pulled into the root module (instead of a lazy route) is counted in the initial bundle, so the total crosses the budget only in the production build CI runs.
How to fix it
Reduce the initial bundle or raise the budget deliberately
- Run
ng build --configuration production --stats-jsonand inspect what grew. - Lazy load the offending feature module via a route loadChildren.
- If the growth is legitimate, raise
maximumErrorin the budgets entry rather than silently disabling it.
"budgets": [
{
"type": "initial",
"maximumWarning": "600kb",
"maximumError": "1mb"
}
]Analyze the bundle to find the regression
Use source-map-explorer or the stats output to see which import added weight, then defer or drop it.
ng build --configuration production --source-map
npx source-map-explorer dist/**/*.jsHow to prevent it
- Keep budgets in angular.json realistic and reviewed, not far above real size.
- Lazy load feature modules so the initial bundle stays small.
- Track bundle size in CI so a regression is caught in review, not after merge.