vue-prettier
raw JSON → 0.2.0 verified Sat Apr 25 auth: no javascript deprecated
vue-prettier (v0.2.0) is a CLI tool to format .vue single-file components using Prettier. It parses Vue template, script, and style sections individually via vue-template-compiler rather than regex, enabling reliable formatting. Designed as a temporary solution until native Prettier Vue support arrived (which it now has). The package uses the same CLI arguments as Prettier, allowing drop-in replacement. Requires Node >=8 and vue-template-compiler as a peer dependency. Project has seen no updates since 2019 and is effectively superseded by Prettier's built-in Vue support (via @prettier/plugin-vue) since Prettier v1.15+.
Common errors
error Error: Cannot find module 'vue-template-compiler' ↓
cause Missing peer dependency vue-template-compiler
fix
npm install --save-dev vue-template-compiler
error TypeError: formatFile is not a function ↓
cause Incorrect import (ESM import on CommonJS package)
fix
Use const { formatFile } = require('vue-prettier');
error Error: ENOENT: no such file or directory, open 'component.vue' ↓
cause File path is incorrect or file does not exist
fix
Ensure the file path is correct relative to the working directory.
Warnings
deprecated vue-prettier is deprecated; Prettier now natively supports Vue via @prettier/plugin-vue. ↓
fix Use Prettier >=1.15 with the Vue plugin or Prettier >=2.0 which includes built-in Vue support.
breaking Package requires vue-template-compiler as a peer dependency; missing it causes runtime errors. ↓
fix Run: npm install --save-dev vue-template-compiler
gotcha CLI executable is named 'vue-prettier', not 'prettier'. If used as a drop-in replacement, scripts referencing 'prettier' will not work. ↓
fix Update scripts to use 'vue-prettier' command, or symlink.
gotcha No Windows support; only tested on Unix-like systems. ↓
fix Consider using WSL or another tool on Windows.
deprecated Project was last updated in 2019; no longer maintained. ↓
fix Switch to Prettier's native Vue support.
Install
npm install vue-prettier yarn add vue-prettier pnpm add vue-prettier Imports
- CLI as vue-prettier
const vuePrettier = require('vue-prettier'); - formatFile wrong
import { formatFile } from 'vue-prettier';correctconst { formatFile } = require('vue-prettier'); - default wrong
import vuePrettier from 'vue-prettier';correctconst vuePrettier = require('vue-prettier').default;
Quickstart
// Save as format.vue and run: node format.vue
const { formatFile } = require('vue-prettier');
const fs = require('fs');
const source = fs.readFileSync('component.vue', 'utf8');
formatFile(source, { parser: 'vue' }).then(result => {
console.log(result.formatted);
}).catch(err => {
console.error(err);
});