angular/angular-cli · error · Error

${errors.join('\n')}

Error message

${errors.join('\n')}

What it means

`formatFiles` formats a batch of files (with Prettier) and collects every per-file formatting error instead of failing on the first one. After processing, if the `errors` array is non-empty it throws a single `Error` whose message is all collected error messages joined by newlines, so callers see every failure at once. This batches failures from schematic runs (`runSchematic`) and package migrations (`executePackageMigrations`).

Source

Thrown at packages/angular/cli/src/utilities/prettier.ts:120

  // Spawn Prettier once per batch so repositories with many changed files do not
  // overflow the OS command-line length limit. A failure in one batch (e.g. a file
  // Prettier cannot parse) must not stop the remaining batches, matching the previous
  // single-invocation behavior, so errors are collected and reported together.
  const errors: string[] = [];
  for (const batch of batchFilesByArgumentLength(files, baseLength, MAX_COMMAND_LINE_LENGTH)) {
    try {
      await execFileAsync(process.execPath, [...baseArgs, ...batch], {
        cwd,
        shell: false,
      });
    } catch (error) {
      errors.push(error instanceof Error ? error.message : String(error));
    }
  }

  if (errors.length > 0) {
    throw new Error(errors.join('\n'));
  }
}

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Read each line of the joined message — it contains one underlying error per failed file — and fix the listed files.
  2. Run Prettier directly on the reported files (`npx prettier --check <file>`) to reproduce and see the full parser error.
  3. Fix the generator/template that produced unparseable output and re-run the schematic/migration.
  4. Pin a Prettier version compatible with your codebase's syntax, and format generated code in CI to catch issues early.

Example fix

// error message
Unexpected token (1:5)
Cannot format file: invalid.css
// fix the reported file, then re-run
npx prettier --write src/broken-file.ts
ng generate ...  # re-run schematic
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-validate generated files parse before running schematics/migrations:
for (const f of generatedFiles) {
  try { ts.createSourceFile(f, readFileSync(f, 'utf8'), ts.ScriptTarget.Latest, true); }
  catch (e) { throw new Error(`Generated file ${f} will fail formatting: ${e}`); }
}

Type guard

function isBatchFormatError(e: unknown): e is Error {
  return e instanceof Error && e.message.split('\n').length > 1 && /format|parse|prettier/i.test(e.message);
}

Try / catch

try {
  await runSchematic(...);
} catch (e) {
  if (e instanceof Error) {
    const perFileErrors = e.message.split('\n'); // one entry per failed file
    for (const msg of perFileErrors) console.error(msg);
  } else { throw e; }
}

Prevention

When it happens

Trigger: Running a schematic or migration (via `runSchematic`/`executePackageMigrations`) where formatting one or more touched files with Prettier throws — e.g. syntax errors in generated files, files that Prettier cannot parse, or formatter exceptions.

Common situations: A custom schematic generating syntactically invalid TypeScript/HTML; files with unsupported syntax for the installed Prettier version; concurrently modified files during migrations; generators emitting malformed templates.

Related errors


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