prettier-plugin-yaml
raw JSON → 1.1.3 verified Sat Apr 25 auth: no javascript
A Prettier plugin providing additional YAML formatting options beyond Prettier's built-in support. Current stable version is 1.1.3. It adds options like yamlBlockStyle, yamlCollectionStyle, yamlQuoteKeys, and yamlQuoteValues. Released under MIT, it has a frequent release cadence with 6+ versions. Key differentiators: no dependencies beyond Prettier 3+, TypeScript types included, and addresses CVE-2026-33532 in the underlying yaml library. It is ESM-only and requires Node >=20.
Common errors
error TypeError: The 'Plugin' interface was incorrectly exported ↓
cause Using v1.1.1 where the Plugin export was malformed.
fix
Update to v1.1.2+: npm install prettier-plugin-yaml@1.1.2
error Error [ERR_REQUIRE_ESM]: require() of ES Module ↓
cause Attempting to use require() on an ESM-only package.
fix
Use import syntax or set type: module in package.json.
error Error: Cannot find module 'prettier-plugin-yaml' ↓
cause Plugin not installed or not configured in Prettier config.
fix
Run npm install --save-dev prettier-plugin-yaml and add 'prettier-plugin-yaml' to the plugins array in .prettierrc.
Warnings
breaking The package is ESM-only. Use `import` syntax, not `require()`, and ensure `"type": "module"` in package.json or use .mjs extension. ↓
fix Add `"type": "module"` to your package.json or use .mjs files when importing the plugin programmatically.
breaking The `Plugin` named export was incorrectly re-exported as a non-interface in v1.1.1. This was fixed in v1.1.2. ↓
fix Upgrade to v1.1.2 or later: npm install prettier-plugin-yaml@latest
deprecated All options are stable; no known deprecations as of v1.1.3. ↓
fix No action needed.
gotcha If using other YAML Prettier plugins, prettier-plugin-yaml must be listed last in the plugins array to take effect. ↓
fix Ensure other YAML plugins appear before prettier-plugin-yaml in the plugins array.
gotcha The yamlQuoteValues option does not apply to strings that are valid numeric or boolean representations; those remain unquoted. ↓
fix If you need all strings quoted, consider using yamlQuoteValues with additional manual overrides.
Install
npm install prettier-plugin-yaml yarn add prettier-plugin-yaml pnpm add prettier-plugin-yaml Imports
- Plugin wrong
const Plugin = require('prettier-plugin-yaml')correctimport { Plugin } from 'prettier-plugin-yaml' - options wrong
const { options } = require('prettier-plugin-yaml')correctimport { options } from 'prettier-plugin-yaml' - PluginOptions wrong
import { PluginOptions } from 'prettier-plugin-yaml'correctimport type { PluginOptions } from 'prettier-plugin-yaml'
Quickstart
// Install: npm install --save-dev prettier prettier-plugin-yaml
// Add to .prettierrc:
{
"plugins": ["prettier-plugin-yaml"],
"yamlQuoteKeys": true
}
// Then run: npx prettier --write file.yaml