{"id":20639,"library":"unified-prettier","title":"unified-prettier","description":"A unified plugin that formats output using Prettier. Current stable version is 2.0.1, released in 2024. It integrates with remark-cli, rehype-cli, or any unified-engine based tool to automatically run Prettier on processed files. Key differentiators: it uses Prettier's configuration file by default, supports Prettier plugins, and is fully typed with TypeScript. Unlike running Prettier separately, it ensures formatting happens as part of the unified pipeline, reducing overhead. Requires Node.js >=16, Prettier ^3.0.0, and unified ^11.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/remcohaszing/unified-prettier","tags":["javascript","prettier","rehype","rehype-plugin","remark","remark-plugin","unified","unified-plugin","typescript"],"install":[{"cmd":"npm install unified-prettier","lang":"bash","label":"npm"},{"cmd":"yarn add unified-prettier","lang":"bash","label":"yarn"},{"cmd":"pnpm add unified-prettier","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for formatting. Must be version ^3.0.0.","package":"prettier","optional":false}],"imports":[{"note":"ESM-only since v2.0.0. Default export is the plugin function.","wrong":"const unifiedPrettier = require('unified-prettier')","symbol":"unifiedPrettier","correct":"import unifiedPrettier from 'unified-prettier'"},{"note":"For TypeScript, use type imports for the unified Plugin type separately; unified-prettier doesn't export its own types for options.","symbol":"unifiedPrettier (type)","correct":"import type { Plugin } from 'unified'; import unifiedPrettier from 'unified-prettier'"},{"note":"No named export for options. Use inline object or Prettier config file.","wrong":"import { Options } from 'unified-prettier'","symbol":"PluginOptions","correct":"// Options can be passed inline: remark().use(unifiedPrettier, { semi: false })"}],"quickstart":{"code":"import { remark } from 'remark'\nimport { read } from 'to-vfile'\nimport unifiedPrettier from 'unified-prettier'\n\nconst processor = remark().use(unifiedPrettier, { semi: false })\nconst file = await read('README.md')\nconst { value } = await processor.process(file)\nconsole.log(value)","lang":"typescript","description":"Shows basic usage of unified-prettier with remark to format a markdown file, including passing Prettier options."},"warnings":[{"fix":"Upgrade unified to version 11 or stay on unified-prettier 1.x.","message":"v2.0.0 requires unified 11, breaking compatibility with unified 10.","severity":"breaking","affected_versions":">=2.0.0 <3.0.0"},{"fix":"Use Node.js 16 or later.","message":"v2.0.0 drops support for Node.js <16.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use dynamic import() or switch to ESM.","message":"v2.0.0 switches to ESM-only. CommonJS require() will not work.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"No action needed, but note that asynchronous Prettier API is not used.","message":"v1.x used @prettier/sync internally; v2 uses Prettier's synchronous API.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Ensure the vfile has a path (or set it via file.path).","message":"The plugin formats only if a file path is provided in the vfile; otherwise it is ignored since v2.0.1.","severity":"gotcha","affected_versions":">=2.0.1"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Switch to import syntax, or set type: module in package.json, or downgrade to v1.x.","cause":"Using require() on an ESM-only package (v2.0.0+).","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Run npm install prettier@^3.0.0.","cause":"Peer dependency prettier is not installed.","error":"Error: Cannot find module 'prettier'"},{"fix":"Ensure vfile.path is set, or expect that the output is unchanged without formatting.","cause":"No file path set in vfile, and formatting is skipped. Attempting to access formatted output that doesn't exist.","error":"TypeError: Cannot read properties of undefined (reading 'format')"},{"fix":"Use import unifiedPrettier from 'unified-prettier'.","cause":"Using import { unifiedPrettier } from 'unified-prettier' instead of default import.","error":"Error: You have used a named export instead of default export"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}