{"record":{"id":"2942b1d51e72b1b4","repo":"angular/angular-cli","slug":"cannot-add-provider-to-invalid-bootstrapapplicatio","errorCode":null,"errorMessage":"Cannot add provider to invalid bootstrapApplication call in ${bootstrapCall.getSourceFile().fileName}","messagePattern":"Cannot add provider to invalid bootstrapApplication call in (.+?)","errorType":"exception","errorClass":"SchematicsException","httpStatus":null,"severity":"error","filePath":"packages/schematics/angular/utility/standalone/rules.ts","lineNumber":177,"sourceCode":"        ...additionalRules,\n        (tree) => insertStandaloneRootProvider(tree, mainFilePath, wrapped.expression),\n      ]);\n    },\n  ]);\n}\n\n/**\n * Inserts a string expression into the root of a standalone project.\n * @param tree File tree used to modify the project.\n * @param mainFilePath Path to the main file of the project.\n * @param expression Code expression to be inserted.\n */\nfunction insertStandaloneRootProvider(tree: Tree, mainFilePath: string, expression: string): void {\n  const bootstrapCall = findBootstrapApplicationCall(tree, mainFilePath);\n  const appConfig = findAppConfig(bootstrapCall, tree, mainFilePath);\n\n  if (bootstrapCall.arguments.length === 0) {\n    throw new SchematicsException(\n      `Cannot add provider to invalid bootstrapApplication call in ${\n        bootstrapCall.getSourceFile().fileName\n      }`,\n    );\n  }\n\n  if (appConfig) {\n    addProvidersExpressionToAppConfig(tree, appConfig, expression);\n\n    return;\n  }\n\n  const newAppConfig = `, {\\n${' '.repeat(2)}providers: [${expression}]\\n}`;\n  let targetCall: ts.CallExpression;\n\n  if (bootstrapCall.arguments.length === 1) {\n    targetCall = bootstrapCall;\n  } else if (isMergeAppConfigCall(bootstrapCall.arguments[1])) {","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/schematics/angular/utility/standalone/rules.ts#L159-L195","documentation":"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.","triggerScenarios":"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.","commonSituations":"Minimal standalone apps bootstrapped without an appConfig; hand-written main.ts omitting the config object; libraries' install schematics mutating simplified entry points.","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)."],"exampleFix":"// before\nbootstrapApplication(AppComponent);\n// after\nbootstrapApplication(AppComponent, { providers: [provideHttpClient()] });","handlingStrategy":"validation","validationCode":"const main = fs.readFileSync('src/main.ts', 'utf8');\nif (/bootstrapApplication\\([^,)]+\\)\\s*;?/.test(main)) {\n  console.warn('bootstrapApplication lacks a config object; add { providers: [] } before running schematics.');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["angular","standalone","schematics","bootstrap"],"backgroundTag":"invalid-bootstrap-call","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}