{"id":20282,"library":"prettier-cli","title":"prettier-cli","description":"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.","status":"active","version":"0.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/prettier/prettier","tags":["javascript"],"install":[{"cmd":"npm install prettier-cli","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-cli","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-cli","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core formatting engine; prettier-cli is a wrapper around Prettier's API.","package":"prettier","optional":false}],"imports":[{"note":"Prettier is ESM-only since v3; require() will fail.","wrong":"const prettier = require('prettier')","symbol":"default","correct":"import prettier from 'prettier'"},{"note":"check is a named export, not default.","wrong":"import check from 'prettier'","symbol":"check","correct":"import { check } from 'prettier'"},{"note":"Named export, ESM-only since v3.","wrong":"const format = require('prettier').format","symbol":"format","correct":"import { format } from 'prettier'"}],"quickstart":{"code":"#!/usr/bin/env node\nimport { format } from 'prettier';\nimport fs from 'fs';\n\nconst code = fs.readFileSync('input.js', 'utf8');\nconst formatted = await format(code, { parser: 'babel' });\nconsole.log(formatted);","lang":"javascript","description":"Demonstrates basic usage of Prettier's format function to format a JavaScript file."},"warnings":[{"fix":"Switch to ESM imports or use dynamic import().","message":"Prettier v3 is ESM-only; CommonJS require() will throw.","severity":"breaking","affected_versions":">=3.0"},{"fix":"Use `prettier --write file.js` instead of `prettier --write .` without arguments.","message":"Prettier's CLI `--write` flag is deprecated in favor of `--write` with explicit file list.","severity":"deprecated","affected_versions":">=2.0"},{"fix":"Always review diffs before committing.","message":"Prettier may reformat code even when --check is used; ensure your code is actually formatted.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Run Prettier before ESLint to avoid conflicts.","message":"Prettier does not lint code; it only formats. Use with ESLint for full code quality.","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use ESM imports (import ... from 'prettier') or use dynamic import() in CommonJS.","cause":"Using require() to import Prettier v3 which is ESM-only.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ... from ... not supported."},{"fix":"Use the correct parser (e.g., 'babel' for JSX) and ensure Prettier is up-to-date.","cause":"Prettier does not support all modern JavaScript syntax by default.","error":"SyntaxError: Unexpected token '??='"},{"fix":"Run `npm install prettier` to install the package.","cause":"Prettier not installed or not in node_modules.","error":"Cannot find module 'prettier'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}