{"id":20464,"library":"prettier-ts","title":"Prettier","description":"Prettier is an opinionated code formatter that supports JavaScript, TypeScript, CSS, HTML, GraphQL, Markdown, YAML, and many other languages via plugins. The current stable version is 3.8.3 (as of early 2025). It enforces a consistent style by parsing code and re-printing it with its own rules, taking maximum line length into account. Key differentiators: it eliminates debates over code style by being opinionated, integrates with editors and CI via pre-commit hooks, and supports a wide ecosystem of plugins. Released under MIT license, available as an npm package with weekly downloads exceeding 50 million.","status":"active","version":"1.17.1-2","language":"javascript","source_language":"en","source_url":"https://github.com/prettier/prettier","tags":["javascript"],"install":[{"cmd":"npm install prettier-ts","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-ts","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-ts","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Prettier v3 is ESM-only. When using CommonJS, use dynamic import: const prettier = await import('prettier'). For older versions (v2), require() works.","wrong":"const prettier = require('prettier')","symbol":"prettier","correct":"import * as prettier from 'prettier'"},{"note":"Named export for formatting a string. In CommonJS, use destructuring from dynamic import.","wrong":"const format = require('prettier').format","symbol":"format","correct":"import { format } from 'prettier'"},{"note":"Resolves configuration from a file path. Returns a config object or null.","symbol":"resolveConfig","correct":"import { resolveConfig } from 'prettier'"},{"note":"check is a named export from 'prettier' since v3, not a separate module.","wrong":"import { check } from 'prettier/check'","symbol":"check","correct":"import { check } from 'prettier'"}],"quickstart":{"code":"import { format, resolveConfig } from 'prettier';\n\nasync function formatCode(code, filepath) {\n  const options = await resolveConfig(filepath);\n  const formatted = await format(code, {\n    ...options,\n    parser: 'babel',\n    filepath\n  });\n  console.log(formatted);\n}\n\nformatCode('const x = { foo: \"bar\" }', 'example.js');","lang":"typescript","description":"Demonstrates async formatting with config resolution. Parses source as JavaScript and applies Prettier rules."},"warnings":[{"fix":"Upgrade Node.js to version 14.17.0 or higher.","message":"Prettier v3 drops Node.js 12 support, requires Node >= 14.17.0.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Change parser option from 'typescript' to 'babel-ts' or 'typescript' (still valid but no longer an alias).","message":"Prettier v3 removes the 'typescript' parser alias; use 'babel-ts' or 'typescript' explicitly.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Replace import 'prettier/standalone' with 'prettier/standalone' (note: no change in path, but the old global isn't available).","message":"Use of `prettier.standalone` standalone build is deprecated; use `prettier/standalone` module instead.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Ensure all calls to prettier.format are awaited.","message":"Prettier v3 runs asynchronously; use `await format()` not `format()` synchronously.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install prettier: npm install prettier. Use import 'prettier/standalone' if using the standalone build.","cause":"The standalone module path has changed; or the package is not installed.","error":"Cannot find module 'prettier/standalone'"},{"fix":"Use dynamic import: import('prettier').then(p => p.format(...)) or switch to ESM.","cause":"prettier.format is not a function when using older CommonJS require without destructuring or dynamic import.","error":"TypeError: format is not a function"},{"fix":"Provide a valid file path to resolveConfig from the project root.","cause":"resolveConfig is called without a filepath or the config file does not exist.","error":"Resolution failed. No such file or directory: .prettierrc"},{"fix":"Use --semi false instead of --no-semi.","cause":"In Prettier v3, CLI flags changed; --no-semi is replaced by --semi false.","error":"Prettier 2.x vs 3.x: unknown option '--no-semi'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}