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 running package migrations, `ng update` attempts to format all touched files (prettier). If formatFiles throws, the migration itself is still complete and successful; this warning reports the formatting failure with the underlying error message.
Source
Thrown at packages/angular/cli/src/commands/update/utilities/migration.ts:237
switch (files.size) {
case 0:
modifiedFilesText = 'No changes made';
break;
case 1:
modifiedFilesText = '1 file modified';
break;
default:
modifiedFilesText = `${files.size} files modified`;
break;
}
if (files.size) {
try {
await formatFiles(process.cwd(), files);
} catch (error) {
assertIsError(error);
logger.warn(
`WARNING: Formatting of files failed with the following error: ${error.message}`,
);
}
}
logger.info(` Migration completed (${modifiedFilesText}).`);
// Commit migration
if (commit) {
const commitPrefix = `${packageName} migration - ${migration.name}`;
const commitMessage = migration.description
? `${commitPrefix}\n\n${migration.description}`
: commitPrefix;
const committed = commitChanges(logger, commitMessage);
if (!committed) {
// Failed to commit, something went wrong. Abort the update.
return 1;
}View on GitHub (pinned to bb72145f9a)
Solutions
- Read the inner error.message and fix the specific file it complains about (usually a syntax issue).
- Run prettier manually on the affected files to see the full error.
- Check/repair your prettier config (.prettierrc, overrides).
- Ensure files are writable and not locked; then rerun the migration or format manually.
Example fix
// before (.prettierrc)
{ "parser": "not-a-real-parser" }
// after
{ "printWidth": 100 } Defensive patterns
Strategy: try-catch
Validate before calling
const filesArr = [...files]; const bad = filesArr.filter(f => !fs.existsSync(f) || !fs.accessSync(f, fs.constants.W_OK)); if (bad.length) throw new Error(`unwritable: ${bad}`); Type guard
function assertIsError(e: unknown): asserts e is Error { if (!(e instanceof Error)) throw e; } Try / catch
try { await formatFiles(process.cwd(), files); } catch (error) { assertIsError(error); logger.warn(`WARNING: Formatting of files failed with the following error: ${error.message}`); } Prevention
- Keep prettier config valid and minimal.
- Fix syntax errors in generated/migrated files before formatting.
- Ensure migrated files are writable and not locked.
- Run prettier manually on the workspace regularly to catch issues early.
When it happens
Trigger: `formatFiles(process.cwd(), files)` throws — e.g. a file with syntax prettier cannot parse, unreadable file permissions, or a prettier configuration error in the workspace.
Common situations: Migrations touching generated or malformed code prettier can't parse; a broken .prettierrc; files locked by an editor/AV on Windows; low disk space.
Related errors
- ${errors.join('\n')}
- WARNING: Formatting of files failed with the following error
- Cannot update project "${projectName}" to use the applicatio
- Cannot update project "${projectName}" to use the applicatio
- Project "${options.project}" is configured to use Karma. Ple
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/83b97bcc9677431f.
Report an issue: GitHub.