angular/angular-cli · error · Error

Invalid Webpack stats configuration.

Error message

Invalid Webpack stats configuration.

What it means

webpackStatsLogger prints formatted build stats. It requires config.stats to be an options object so it can compute which fields to print. If stats is a string preset (like 'minimal' or 'errors-only') or otherwise not an object, the formatter can't proceed and throws.

Source

Thrown at packages/angular_devkit/build_angular/src/tools/webpack/utils/stats.ts:357

    initialChunksCount,
    changedChunksCount,
    durationInMs: getBuildDuration(webpackStats),
    cssSizeInBytes,
    jsSizeInBytes,
    ngComponentCount,
  };
}

export function webpackStatsLogger(
  logger: logging.LoggerApi,
  json: StatsCompilation,
  config: Configuration,
  budgetFailures?: BudgetCalculatorResult[],
): void {
  logger.info(statsToString(json, config.stats, budgetFailures));

  if (typeof config.stats !== 'object') {
    throw new Error('Invalid Webpack stats configuration.');
  }

  if (statsHasWarnings(json)) {
    logger.warn(statsWarningsToString(json, config.stats));
  }

  if (statsHasErrors(json)) {
    logger.error(statsErrorsToString(json, config.stats));
  }
}

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Set `stats` in your webpack config to an object (e.g. { all: false, errors: true, warnings: true }).
  2. Remove custom `stats` overrides so the CLI's default stats object is used.
  3. If using a custom builder, pass a resolved stats object into webpackStatsLogger instead of a string.
  4. Check for plugins that rewrite config.stats to a string preset and disable them.

Example fix

// before
module.exports = { stats: 'minimal' };
// after
module.exports = { stats: { all: false, errors: true, warnings: true, assets: true } };
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof config.stats !== 'object' || config.stats === null) {
  throw new TypeError('webpack config.stats must be an options object for webpackStatsLogger');
}

Type guard

function isStatsObject(stats: Configuration['stats']): stats is StatsOptions {
  return typeof stats === 'object' && stats !== null && !Array.isArray(stats);
}

Try / catch

try {
  webpackStatsLogger(logger, stats, config);
} catch (err) {
  if (err.message === 'Invalid Webpack stats configuration.') {
    logger.warn('stats was not an object; defaulting to verbose stats');
  } else throw err;
}

Prevention

When it happens

Trigger: Calling webpackStatsLogger with a webpack Configuration whose `stats` field is a string preset or undefined/non-object — typically from custom webpack builder configs passing `stats: 'minimal'` or similar.

Common situations: Custom webpack configs copied from generic webpack examples where string stats presets are common; programmatic use of the browser/webpack builder with hand-built Configuration objects.

Related errors


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