Registry / web-framework / unified-prettier

unified-prettier

JSON →
library2.0.1jsnpmunverified

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.

npm install unified-prettier
INSTALL
IMPORT
SIG · UNIFIED-PRETTIER
U
unified-prettier
web-frameworkjavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

unifiedPrettier
import unifiedPrettier from 'unified-prettier'
const unifiedPrettier = require('unified-prettier')
ESM-only since v2.0.0. Default export is the plugin function.
unifiedPrettier (type)
import type { Plugin } from 'unified'; import unifiedPrettier from 'unified-prettier'
For TypeScript, use type imports for the unified Plugin type separately; unified-prettier doesn't export its own types for options.
PluginOptions
// Options can be passed inline: remark().use(unifiedPrettier, { semi: false })
import { Options } from 'unified-prettier'
No named export for options. Use inline object or Prettier config file.

Shows basic usage of unified-prettier with remark to format a markdown file, including passing Prettier options.

import { remark } from 'remark' import { read } from 'to-vfile' import unifiedPrettier from 'unified-prettier' const processor = remark().use(unifiedPrettier, { semi: false }) const file = await read('README.md') const { value } = await processor.process(file) console.log(value)
Debug
Known issues
breakingv2.0.0 requires unified 11, breaking compatibility with unified 10.
fix
Upgrade unified to version 11 or stay on unified-prettier 1.x.
affects: >=2.0.0 <3.0.0
breakingv2.0.0 drops support for Node.js <16.
fix
Use Node.js 16 or later.
affects: >=2.0.0
breakingv2.0.0 switches to ESM-only. CommonJS require() will not work.
fix
Use dynamic import() or switch to ESM.
affects: >=2.0.0
deprecatedv1.x used @prettier/sync internally; v2 uses Prettier's synchronous API.
fix
No action needed, but note that asynchronous Prettier API is not used.
affects: >=2.0.0
gotchaThe plugin formats only if a file path is provided in the vfile; otherwise it is ignored since v2.0.1.
fix
Ensure the vfile has a path (or set it via file.path).
affects: >=2.0.1
Errors
Common errors & fixes
SyntaxError: Unexpected token 'export'
Using require() on an ESM-only package (v2.0.0+).
fix
Switch to import syntax, or set type: module in package.json, or downgrade to v1.x.
Error: Cannot find module 'prettier'
Peer dependency prettier is not installed.
fix
Run npm install prettier@^3.0.0.
TypeError: Cannot read properties of undefined (reading 'format')
No file path set in vfile, and formatting is skipped. Attempting to access formatted output that doesn't exist.
fix
Ensure vfile.path is set, or expect that the output is unchanged without formatting.
Error: You have used a named export instead of default export
Using import { unifiedPrettier } from 'unified-prettier' instead of default import.
fix
Use import unifiedPrettier from 'unified-prettier'.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
prettierrequiredPeer dependency required for formatting. Must be version ^3.0.0.
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
unified-prettier — npm install unified-prettier · libregistry