angular/angular-cli · error · SchematicsException
Cannot add provider to invalid bootstrapApplication call in
Error message
Cannot add provider to invalid bootstrapApplication call in ${bootstrapCall.getSourceFile().fileName} What it means
insertStandaloneRootProvider adds a provider expression to the bootstrapApplication call in main.ts. It first finds the app config object (the second argument of bootstrapApplication). If the call has zero arguments, there is no config to attach the provider to and it throws this error identifying the offending file.
Source
Thrown at packages/schematics/angular/utility/standalone/rules.ts:177
...additionalRules,
(tree) => insertStandaloneRootProvider(tree, mainFilePath, wrapped.expression),
]);
},
]);
}
/**
* Inserts a string expression into the root of a standalone project.
* @param tree File tree used to modify the project.
* @param mainFilePath Path to the main file of the project.
* @param expression Code expression to be inserted.
*/
function insertStandaloneRootProvider(tree: Tree, mainFilePath: string, expression: string): void {
const bootstrapCall = findBootstrapApplicationCall(tree, mainFilePath);
const appConfig = findAppConfig(bootstrapCall, tree, mainFilePath);
if (bootstrapCall.arguments.length === 0) {
throw new SchematicsException(
`Cannot add provider to invalid bootstrapApplication call in ${
bootstrapCall.getSourceFile().fileName
}`,
);
}
if (appConfig) {
addProvidersExpressionToAppConfig(tree, appConfig, expression);
return;
}
const newAppConfig = `, {\n${' '.repeat(2)}providers: [${expression}]\n}`;
let targetCall: ts.CallExpression;
if (bootstrapCall.arguments.length === 1) {
targetCall = bootstrapCall;
} else if (isMergeAppConfigCall(bootstrapCall.arguments[1])) {View on GitHub (pinned to bb72145f9a)
Solutions
- Add an empty config object to the bootstrap call: `bootstrapApplication(AppComponent, {})` and re-run the schematic.
- Manually add the provider to the config: `bootstrapApplication(AppComponent, { providers: [provideX()] })`.
- Keep the app config in the same call so static analysis can find it (or use the standard appConfig const pattern).
Example fix
// before
bootstrapApplication(AppComponent);
// after
bootstrapApplication(AppComponent, { providers: [provideHttpClient()] }); Defensive patterns
Strategy: validation
Validate before calling
const main = fs.readFileSync('src/main.ts', 'utf8');
if (/bootstrapApplication\([^,)]+\)\s*;?/.test(main)) {
console.warn('bootstrapApplication lacks a config object; add { providers: [] } before running schematics.');
} Prevention
- Always bootstrap standalone apps with a config object: bootstrapApplication(App, appConfig).
- Follow the default project layout (appConfig const in main.ts).
- After ng add failures, manually add the provider and re-run.
When it happens
Trigger: Adding a root provider via schematics (e.g. `ng add` of a library using provideXxx, or `ng g @angular/...:provider`) into a main.ts whose `bootstrapApplication(AppComponent)` was written with only one argument.
Common situations: Minimal standalone apps bootstrapped without an appConfig; hand-written main.ts omitting the config object; libraries' install schematics mutating simplified entry points.
Related errors
- Bootstrap call not found
- Could not find bootstrapApplication call in ${mainFilePath}
- Cannot statically analyze bootstrapApplication call in ${boo
- Option "project" is required.
- Project is not defined in this workspace.
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/2942b1d51e72b1b4.
Report an issue: GitHub.