Skip to content

Prettier Not Formatting Code Fix

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about Prettier Not Formatting Code Fix. We cover key concepts, practical examples, and best practices.

The Problem

Prettier does not format your code when saving. The editor either does nothing, formats with the wrong style, or conflicts with ESLint formatting rules.

Quick Fix

Step 1: Verify Prettier is installed

npm install -D prettier
npx prettier --check src/

Expected output: Prettier reports which files are not formatted.

Step 2: Create a config file

// .prettierrc — Wrong: missing config
// Right
{
    "semi": true,
    "singleQuote": true,
    "tabWidth": 4,
    "trailingComma": "all",
    "printWidth": 100
}

Expected output: Prettier applies the configured style.

Step 3: Enable format on save in VS Code

// .vscode/settings.json
{
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "esbenp.prettier-vscode"
}

Expected output: VS Code formats files automatically on save.

Step 4: Resolve ESLint and Prettier conflicts

npm install -D eslint-config-prettier

Add prettier to the end of ESLint extends:

// .eslintrc.js
module.exports = {
    extends: [
        'eslint:recommended',
        'prettier', // must be last
    ],
};

Expected output: All formatting rules from ESLint are disabled, leaving formatting to Prettier.

Step 5: Specify the file types to format

// .prettierignore
node_modules
dist
build
*.min.js
npx prettier --write "src/**/*.{js,jsx,ts,tsx,css,json}"

Expected output: Only matching file types are formatted.

Step 6: Set the correct parser

npx prettier --write src/App.vue --parser vue

Or in config:

{
    "overrides": [
        {
            "files": "*.vue",
            "options": { "parser": "vue" }
        }
    ]
}

Expected output: Vue single-file components are parsed and formatted correctly.

Step 7: Check for conflicting editor extensions

Disable other formatting extensions like JS-CSS-HTML Formatter, Beautify, or ESLint's formatting rules. Only one formatter should be active per language.

Prevention

  • Install Prettier as a dev dependency in every project
  • Create a .prettierrc config file in the project root
  • Add eslint-config-prettier to disable conflicting ESLint rules
  • Set editor.formatOnSave and editor.defaultFormatter in VS Code settings

Common Mistakes with formatting

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead of pattern matching, causing runtime errors on empty lists

These mistakes appear frequently in real-world PRETTIER code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does Prettier format differently in different editors?

Each editor uses its own Prettier instance. VS Code uses the prettier from node_modules if available, otherwise the bundled extension version. CI uses the version in devDependencies. Ensure the same Prettier version is used everywhere.

How do I prevent Prettier from formatting specific files?

Add file patterns to .prettierignore (same syntax as .gitignore). Prettier ignores these files entirely. For inline disabling, use <!-- prettier-ignore --> in HTML or // prettier-ignore in JavaScript.

Should I use Prettier with ESLint?

Yes, with eslint-config-prettier. ESLint handles code quality rules (no-unused-vars). Prettier handles formatting (semicolons, quotes). The prettier config disables all ESLint rules that overlap with formatting, preventing conflicts.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro