How to Fix Prettier Not Formatting in VS Code
In this tutorial, you'll learn about How to Fix Prettier Not Formatting in VS Code. We cover key concepts, practical examples, and best practices.
The Problem
You press Shift+Alt+F or save a file in VS Code and nothing happens — the code doesn't format. Or Prettier formats some files but not others. This usually happens because Prettier isn't set as the default formatter, format-on-save is disabled, or another extension is overriding Prettier. Sometimes the Prettier extension itself is installed but silently failing because it can't find a config file or is being ignored by editor settings.
Quick Fix
1. Set Prettier as the default formatter in VS Code settings
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
Open Command Palette (Ctrl+Shift+P) → Preferences: Open Settings (JSON) and add these lines. The editor.defaultFormatter must be set to Prettier's extension ID: esbenp.prettier-vscode.
2. Verify the Prettier extension is installed and enabled
# Check if the extension is installed
code --list-extensions | grep prettier
Expected output:
esbenp.prettier-vscode
If not installed: ext install esbenp.prettier-vscode or search for "Prettier - Code formatter" in the VS Code extensions panel.
3. Check for formatter conflicts
Open Command Palette → Format Document With... and select Prettier. If another formatter (like Beautify, JS-CSS-HTML Formatter, or the built-in TypeScript formatter) is set as default, Prettier won't run.
// Disable other formatters for overlapping languages
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
4. Ensure Prettier config exists in your project
# Create a minimal config file
echo {} > .prettierrc
Prettier requires a config file in your project root. An empty {} uses default settings. Without a config file, Prettier looks up the directory tree and may use VS Code's built-in settings instead.
5. Check if Prettier is ignoring your file
# Check if a file is ignored
npx prettier --check src/app.js
Expected output (if ignored):
src/app.js[error] src/app.js: There are no files matching the prettier ignore pattern.
Check .prettierignore in your project root. If it matches your file, add the file or remove the ignore pattern.
6. Restart the Prettier server in VS Code
Command Palette → Prettier: Restart Prettier Server. This reloads the Prettier process and picks up config changes without reloading the VS Code window.
7. Format a specific selection or file manually
# Format a file from the command line
npx prettier --write src/app.js
Expected output:
src/app.js 123ms
If CLI formatting works but the editor doesn't format, the problem is in VS Code settings or extension state.
8. Enable format on save for specific languages only
{
"[javascript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[markdown]": {
"editor.formatOnSave": false
}
}
Language-specific settings give you fine-grained control. You might want Prettier for JS/TS/CSS but not for Markdown or YAML.
Prevention
- Set
editor.formatOnSave: trueandeditor.defaultFormatter: "esbenp.prettier-vscode"globally - Create a
.prettierrcfile in every project - Add a
.prettierignorefile to exclude build artifacts - Use
npx prettier --check .in CI to enforce formatting - Avoid installing multiple formatter extensions for the same language
- Use language-specific settings to disable formatting for file types where it causes issues
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro