Pinning Prettier to Avoid Format Drift
Pinning an exact Prettier version keeps output identical across developers and CI so format checks do not drift.
Prettier output can change between releases. If CI and laptops run different versions, a file that passes in one place fails in another. Pinning removes that ambiguity.
What it does
Prettier output is deterministic for a given version, but minor and major releases sometimes change formatting (for example the trailingComma default changed to all in 3.0). Pinning the exact version, via a devDependency plus a committed lockfile, guarantees every machine and CI run produces the same output and the same --check result.
Common usage
// package.json
{
"devDependencies": {
"prettier": "3.3.3"
}
}
# install the locked version, then check
npm ci
npx prettier --check .Options
| Practice | What it does |
|---|---|
| Exact version in devDependencies | No caret, so npm install does not float it |
| Commit the lockfile | Pins the resolved version for npm ci |
| npm ci in CI | Installs exactly the locked versions |
| Pin plugins too | Plugin output changes also cause drift |
In CI
Run npm ci (not npm install) so CI installs the locked Prettier version. Include the Prettier version in any format cache key so an upgrade busts the cache. When you bump Prettier, run prettier --write . in the same commit so the new output lands together with the version change.
Common errors in CI
The signature symptom is a file that passes locally but fails prettier --check in CI with "Code style issues found", caused by a newer or older Prettier running in one place. Confirm with npx prettier --version on both sides. A global Prettier shadowing the local one is a frequent culprit; always invoke the project-local binary via npx or the package script.