prettier --check fails: code style issues found in N files
Fixes prettier check failures that block PR review. Use when the style gate lists files with code style issues, so you can apply prettier's formatting with the write flag and re-run the check to a clean pass. Key trigger: prettier check exiting nonzero with a file list.
TL;DR
prettier --check fails when files do not match prettier's style; the fix is to let prettier rewrite them with prettier --write. Run write on the repo, re-run check, and expect the all-clean message. Then make sure your editor uses the same config so it stays clean.
$ npx prettier --check .
Checking formatting...
[warn] src/app.js
[warn] src/util.js
[warn] Code style issues found in 2 files. Forgot to run Prettier?- See the full list:
npx prettier --check .(the same command CI runs). Expected: one[warn]line per offending file plus the summary count. - Fix them:
npx prettier --write .. Expected: each file prints with its timing, for examplesrc/app.js 12ms. - Verify:
npx prettier --check .again. Expected:All matched files use Prettier code style!and exit code 0. - Commit the reformatted files and push. Expected: the style gate passes.
- Stop the recurrence: confirm the repo's prettier config file is committed and your editor's format-on-save points at the repo's prettier version.
Use this when
- The PR style gate fails with prettier's file list
- You want the exact write command that fixes it
- The failure count is small and mechanical
Not for this skill when
- The failure is eslint, not prettier; different tool, different fix
- prettier and eslint rules fight each other; hand style to prettier via eslint-config-prettier
- The repo has no prettier config; adding one is a team decision, not a PR fix
Variant phrasings
- "prettier check fails how to fix"
- "code style issues found in N files prettier"
- "prettier write versus check"
Why it happens
prettier is opinionated: one style, no options that matter. Any edit made without prettier (or with a different config) diverges from that style, and --check reports the divergence without changing anything.
Edge cases
- A prettierignore mismatch between local and CI changes the file set; keep the ignore file committed.
- prettier version drift changes output; pin the version in package.json and run via npx so everyone uses the same one.
- If --write reformats huge unrelated sections, the file was never prettier-clean; that is a pre-existing condition worth one cleanup commit, not a reason to skip.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_7c7D3adZ2KXjfskeQ8Qwww