prettier-plugin-merge

raw JSON →
0.10.1 verified Sat Apr 25 auth: no javascript

A Prettier plugin (v0.10.1) that sequentially merges the formatting results of other Prettier plugins, overcoming Prettier's built-in limitation of using only the last applicable plugin per language. It enables combining multiple plugins like Tailwind CSS class sorting, import ordering, or brace style. Requires Prettier v3+ and Node.js 18+. Released under MIT. Maintenance active with regular updates.

error Error: Cannot find module 'prettier-plugin-merge'
cause Missing installation or not in node_modules.
fix
Run npm install -D prettier-plugin-merge
error Error: Cannot use import statement outside a module
cause Using ESM import in CommonJS project.
fix
Add "type": "module" to package.json or use require (if your version supports CJS, but v0.8+ is ESM-only).
error Error: [prettier-plugin-merge] The plugin must be the last in the 'plugins' array.
cause Plugin not listed last in configuration.
fix
Move 'prettier-plugin-merge' to the end of the plugins array in .prettierrc or config.
breaking Dropped support for Prettier v2 in v0.8.0. Upgrade to Prettier v3+.
fix Update Prettier to v3 or later: npm install -D prettier@latest
breaking Increased minimum Node.js version to 18 in v0.8.0.
fix Use Node.js 18 or later: nvm install 18
gotcha The plugin MUST be listed last in the plugins array. If not, preceding plugins may not be merged correctly.
fix Ensure 'prettier-plugin-merge' is the last entry in the plugins array.
gotcha Does not support Markdown and MDX directly; if used with code blocks in Markdown/MDX, unintended formatting may occur.
fix Add an override to clear plugins for *.md and *.mdx files.
deprecated Version 0.7.x and earlier support Prettier v2, but Prettier v2 is now outdated. Migrate to Prettier v3.
fix Upgrade to latest version and Prettier v3.
npm install prettier-plugin-merge
yarn add prettier-plugin-merge
pnpm add prettier-plugin-merge

Shows installation, config file setup, and programmatic usage with multiple plugins merged via prettier-plugin-merge.

// Install: npm install -D prettier prettier-plugin-merge prettier-plugin-tailwindcss prettier-plugin-classnames

// In .prettierrc (JSON)
{
  "plugins": [
    "prettier-plugin-tailwindcss",
    "prettier-plugin-classnames",
    "prettier-plugin-merge"
  ]
}

// Or programmatically (ESM)
import prettier from 'prettier';

const code = `
  <div class="mt-2 p-4 bg-white text-black">
    Hello
  </div>
`;

const formatted = await prettier.format(code, {
  parser: 'html',
  plugins: [
    'prettier-plugin-tailwindcss',
    'prettier-plugin-classnames',
    'prettier-plugin-merge'
  ]
});

console.log(formatted);
// Expected output: Tailwind classes sorted, class names sorted/merged.