Skip to content
Latchkey

prettier --write: Format Files in Place

prettier --write formats matched files and saves the changes to disk.

This is the flag developers run locally and that pre-commit hooks use. CI usually runs --check instead so it never mutates the checkout.

What it does

prettier --write formats each matched file and writes the result back. It prints each file path with the time taken and marks files it changed. Unchanged files are listed as "(unchanged)". It exits 0 on success and non-zero only on a real error such as a syntax error or an unwritable path.

Common usage

Terminal
prettier --write .
prettier --write "src/**/*.{ts,tsx}"
# format only files staged in git
git diff --name-only --cached | xargs prettier --write

Flags

FlagWhat it does
--write / -wFormat and save files in place
--check / -cCheck only, do not write (use this in CI)
--ignore-unknown / -uSkip files with no associated parser instead of erroring
--log-level <level>Control verbosity of the per-file output
--cacheOnly reformat files changed since the last run

In CI

Avoid --write in CI on the main checkout; it changes files and can mask drift. If you auto-fix in a bot job, run prettier --write . then commit the result on a branch. For PR gating, prefer --check so the job fails loudly and the author fixes it.

Common errors in CI

"[error] EACCES: permission denied, open '...'" means the target file or directory is read-only on the runner. "[error] No parser could be inferred for file ..." means an extension Prettier does not recognize; add --ignore-unknown or a plugin. A syntax error prints "[error] SyntaxError: ..." with a line and column and exits non-zero.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →