Skip to content
Latchkey

Prettier Config File: .prettierrc and Friends

Prettier looks up a configuration file from the formatted file upward and merges it with defaults.

A config file pins your team style so every editor and CI run agrees. Prettier supports several filenames and formats; pick one and commit it.

What it does

Prettier searches from each file being formatted up the directory tree for a config: .prettierrc, .prettierrc.json, .prettierrc.yaml, .prettierrc.json5, .prettierrc.js, .prettierrc.cjs, .prettierrc.mjs, prettier.config.js, prettier.config.cjs, prettier.config.mjs, or a "prettier" key in package.json. The nearest one wins, merged over Prettier defaults.

Common usage

.prettierrc.json
// .prettierrc.json
{
  "semi": false,
  "singleQuote": true,
  "printWidth": 100,
  "trailingComma": "all"
}

Options

File / flagWhat it does
.prettierrc(.json/.yaml/.json5)Static config in JSON, YAML, or JSON5
prettier.config.js / .cjs / .mjsJavaScript config (allows comments and logic)
"prettier" in package.jsonInline config without a separate file
--config <path>Use an explicit config file, skipping the search
--no-configIgnore any config file and use defaults only

In CI

Commit exactly one config so local and CI runs format identically. Avoid placing conflicting configs in nested folders unless intentional, since the nearest file wins per directory. Run prettier --check . from the repo root so the same config resolution applies as your editor uses.

Common errors in CI

"[error] Invalid configuration file ...: ..." means malformed JSON or YAML, for example a trailing comma in .prettierrc.json. "[error] Cannot find configuration file: ..." means --config points at a missing path. A .mjs or ESM config that uses require triggers a module error; use import or rename to .cjs.

Related guides

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