prettier-cli
raw JSON → 0.1.0 verified Sat Apr 25 auth: no javascript
A command-line interface for Prettier, an opinionated code formatter. This package is currently a work-in-progress (WIP) and provides a CLI wrapper around Prettier's API. Prettier itself is at version 3.8.3 (January 2026), with a monthly release cadence. Unlike the standalone `prettier` package, this package aims to offer additional CLI features such as progress bars, better error handling, and configuration validation. It is intended for users who want an enhanced CLI experience while leveraging Prettier's formatting capabilities.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module ... from ... not supported. ↓
cause Using require() to import Prettier v3 which is ESM-only.
fix
Use ESM imports (import ... from 'prettier') or use dynamic import() in CommonJS.
error SyntaxError: Unexpected token '??=' ↓
cause Prettier does not support all modern JavaScript syntax by default.
fix
Use the correct parser (e.g., 'babel' for JSX) and ensure Prettier is up-to-date.
error Cannot find module 'prettier' ↓
cause Prettier not installed or not in node_modules.
fix
Run
npm install prettier to install the package. Warnings
breaking Prettier v3 is ESM-only; CommonJS require() will throw. ↓
fix Switch to ESM imports or use dynamic import().
deprecated Prettier's CLI `--write` flag is deprecated in favor of `--write` with explicit file list. ↓
fix Use `prettier --write file.js` instead of `prettier --write .` without arguments.
gotcha Prettier may reformat code even when --check is used; ensure your code is actually formatted. ↓
fix Always review diffs before committing.
gotcha Prettier does not lint code; it only formats. Use with ESLint for full code quality. ↓
fix Run Prettier before ESLint to avoid conflicts.
Install
npm install prettier-cli yarn add prettier-cli pnpm add prettier-cli Imports
- default wrong
const prettier = require('prettier')correctimport prettier from 'prettier' - check wrong
import check from 'prettier'correctimport { check } from 'prettier' - format wrong
const format = require('prettier').formatcorrectimport { format } from 'prettier'
Quickstart
#!/usr/bin/env node
import { format } from 'prettier';
import fs from 'fs';
const code = fs.readFileSync('input.js', 'utf8');
const formatted = await format(code, { parser: 'babel' });
console.log(formatted);