angular/angular-cli · error · SchematicsException

Cannot statically analyze bootstrapApplication call in ${boo

Error message

Cannot statically analyze bootstrapApplication call in ${bootstrapCall.getSourceFile().fileName}

What it means

insertStandaloneRootProvider determines where to inject the new provider: either the bootstrapApplication call itself (1 argument) or its second argument when that is a `mergeApplicationConfig(...)` call. Any other argument shape is not statically analyzable, so the schematic refuses to guess and throws.

Source

Thrown at packages/schematics/angular/utility/standalone/rules.ts:198

      }`,
    );
  }

  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])) {
    targetCall = bootstrapCall.arguments[1];
  } else {
    throw new SchematicsException(
      `Cannot statically analyze bootstrapApplication call in ${
        bootstrapCall.getSourceFile().fileName
      }`,
    );
  }

  applyChangesToFile(tree, mainFilePath, [
    insertAfterLastOccurrence(
      targetCall.arguments,
      newAppConfig,
      mainFilePath,
      targetCall.getEnd() - 1,
    ),
  ]);
}

/**
 * Adds a string expression to an app config object.

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Refactor main.ts to pass a literal object or mergeApplicationConfig(...) call as the second argument, then re-run the schematic.
  2. Manually add the provider into your config factory and skip the automated insert.
  3. Move the config expression inline (e.g. `bootstrapApplication(App, { providers: [...] })`).

Example fix

// before
bootstrapApplication(AppComponent, createAppConfig());
// after
bootstrapApplication(AppComponent, mergeApplicationConfig(createAppConfig(), { providers: [provideX()] }));
Defensive patterns

Strategy: validation

Validate before calling

const main = fs.readFileSync('src/main.ts', 'utf8');
const m = main.match(/bootstrapApplication\([^)]*\)/);
if (m && !/mergeApplicationConfig|\{\s*providers/.test(m[0])) {
  console.warn('Second bootstrapApplication argument is not statically analyzable.');
}

Prevention

When it happens

Trigger: Adding a provider to a standalone app whose second bootstrapApplication argument is neither an object literal / identifiable app config nor a mergeApplicationConfig(...) call — e.g. a function call, conditional expression, or variable from an unresolvable import.

Common situations: Custom config factories: `bootstrapApplication(App, createConfig())`; configs assembled with dynamic spreads or imported via complex re-exports; obfuscated/generated entry files.

Related errors


AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30). Data as JSON: /api/errors/98e33d39ecb2e4b3. Report an issue: GitHub.