angular/angular-cli · warning
WARNING: Formatting of files failed with the following error
Error message
WARNING: Formatting of files failed with the following error: ${error.message} What it means
After a schematic runs, the schematics command tries to format the touched files with the configured formatter (Prettier). If formatFiles throws, runSchematic does not fail the command; instead it logs this warning including the formatter error message, since formatting is a post-generation nicety, not a required step.
Source
Thrown at packages/angular/cli/src/command-builder/schematics-command-module.ts:376
if (!files.size) {
logger.info('Nothing to be done.');
}
if (executionOptions.dryRun) {
logger.warn(`\nNOTE: The "--dry-run" option means no changes were made.`);
return 0;
}
if (files.size) {
// Note: we could use a task executor to format the files but this is simpler.
try {
await formatFiles(this.context.root, files);
} catch (error) {
assertIsError(error);
logger.warn(
`WARNING: Formatting of files failed with the following error: ${error.message}`,
);
}
}
return 0;
} catch (err) {
// In case the workflow was not successful, show an appropriate error message.
if (err instanceof UnsuccessfulWorkflowExecution) {
// "See above" because we already printed the error.
logger.fatal('The Schematic workflow failed. See above.');
} else {
assertIsError(err);
logger.fatal(err.message);
}
return 1;
} finally {View on GitHub (pinned to bb72145f9a)
Solutions
- Inspect the error message appended after the warning — it identifies the file/format problem; fix that file or config.
- Run the formatter directly on the affected files (`npx prettier --write <file>`) to see the full error and correct it.
- Fix .prettierrc issues (invalid options, wrong parser overrides) or add a parser override for custom extensions.
- If the generated code itself is malformed, fix the schematic/template producing it; formatting failure is a symptom.
Example fix
// before (.prettierrc)
{ "parser": "babel" }
// after
{ "overrides": [{ "files": "*.ts", "options": { "parser": "typescript" } }] } Defensive patterns
Strategy: try-catch
Validate before calling
// Validate prettier config parses before generating
import { resolveConfig } from 'prettier';
const cfg = await resolveConfig(process.cwd());
if (cfg === null) console.warn('No prettier config found; formatting may behave unexpectedly'); Try / catch
try {
await ngGenerate(['component', 'hero']);
} catch (e) {
// this warning is logged, not thrown; detect it in CLI output
if (/Formatting of files failed/.test(String(e))) {
console.warn('Generation succeeded but formatting failed; run `npx prettier --write .` manually.');
} else throw e;
} Prevention
- Keep a valid .prettierrc with parsers/overrides for every custom file extension schematics may emit.
- Run `npx prettier --check .` in CI so formatting regressions surface early.
- Treat the warning as non-fatal: files were generated; format them manually with `npx prettier --write .`.
- Fix schematics/templates that emit syntactically invalid code, which is the usual root cause.
When it happens
Trigger: Running `ng generate` where the generated/modified files cannot be formatted — e.g. Prettier hits a parse error on generated content, an unsupported/unreadable file, or the formatter misconfigures (bad .prettierrc, missing parser for extension).
Common situations: Custom schematics generating syntactically invalid placeholder code, files with unusual extensions lacking a Prettier parser, permission issues writing files, or a malformed prettier config in the repo.
Related errors
- ${errors.join('\n')}
- WARNING: Formatting of files failed with the following error
- schematicName cannot be undefined.
- The "not" keyword is not supported in JSON Schema.
- Could not find (/.angular.json)
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/b145c066a465734f.
Report an issue: GitHub.