Skip to content
Latchkey

Prettier "--check" Fails on Ignored Files - Fix .prettierignore in CI

Prettier --check fails when it formats files you never intended to format - build output, generated code, vendored assets. Usually .prettierignore is in the wrong place relative to where Prettier runs, the glob passed on the CLI overrides ignore handling, or the paths simply are not listed.

What this error means

prettier --check . reports formatting issues in dist/, build/, generated files, or node_modules-adjacent output, failing CI even though your source is formatted. The flagged files are ones you do not author.

prettier output
Checking formatting...
[warn] dist/bundle.js
[warn] src/generated/schema.ts
[warn] Code style issues found in 2 files. Run Prettier to fix.
Error: Process completed with exit code 1.

Common causes

.prettierignore not in the run directory

Prettier reads .prettierignore from the current working directory by default. If CI runs Prettier from a different directory (or in a monorepo subpackage), the root ignore file is not applied.

Generated/output paths not ignored

Build output (dist/, build/, .next/), generated code, and snapshots are not listed in .prettierignore, so prettier --check . formats and flags them.

How to fix it

List generated and output paths in .prettierignore

Ignore everything Prettier should not own, in the directory Prettier runs from.

.prettierignore
# .prettierignore
dist/
build/
.next/
coverage/
**/*.generated.ts
package-lock.json

Point Prettier at the right ignore file

Pass --ignore-path explicitly, or narrow the check glob to source only.

Terminal
# explicit ignore path (e.g. reuse .gitignore)
npx prettier --check . --ignore-path .gitignore
# or scope the check to source
npx prettier --check "src/**/*.{ts,tsx,css}"

How to prevent it

  • Keep .prettierignore in the directory Prettier runs from.
  • Ignore build output and generated files explicitly.
  • Scope --check globs to source, or pass --ignore-path.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →