When Prettier Just Fucking Breaks

Q

Why does VS Code show a red error icon and Prettier won't format?

A

Most common cause: Prettier isn't set as your default formatter. The nuclear option that works:

## Kill VS Code completely
killall code

## Reinstall Prettier extension 
code --install-extension esbenp.prettier-vscode --force

Then open VS Code settings (Cmd+, or Ctrl+,) and set:

  • Editor: Default Formatter = Prettier - Code formatter
  • Editor: Format On Save = ✅ Enabled

If you still see red: Check for a rogue package.json in parent directories. This breaks Prettier on simple HTML projects. Delete any unnecessary package.json files above your current folder.

Q

Why does Prettier say "SyntaxError: Unexpected token"?

A

Your code has actual syntax errors. Prettier won't format broken code.

Check these first (in order of how often they fuck up):

  1. Missing semicolons when using "semi": false in config
  2. Unclosed braces/brackets - count them manually
  3. Invalid JSX syntax - mixing HTML and JS incorrectly
  4. ES6 modules mixed with CommonJS (import and require() in same file)

The lazy debug method:

## Run Prettier from command line to see the exact error
npx prettier --check your-broken-file.js

This gives you the line number and exact issue. Much better than the generic VS Code error.

Q

Why does format-on-save work sometimes but not others?

A

File type detection is broken. VS Code can't figure out what language you're writing.

Force the language in the bottom-right corner of VS Code:

  • Click the language indicator (says "Plain Text" or wrong language)
  • Select the correct language (JavaScript, TypeScript, etc.)
  • Save the file again

Permanent fix: Add this to your VS Code settings.json:

{
  "files.associations": {
    "*.js": "javascript",
    "*.jsx": "javascriptreact", 
    "*.ts": "typescript",
    "*.tsx": "typescriptreact"
  }
}
Q

How do I fix "Prettier is taking too long" errors?

A

Prettier 3.6+ performance upgrade:

## Enable the fast CLI (no longer experimental)
npx prettier --write . --cache

For massive codebases (50k+ lines), use the Rust parser:

npm install @prettier/plugin-oxc --save-dev

Add to .prettierrc:

{
  "plugins": ["@prettier/plugin-oxc"]
}

This gives 25x speed improvement on JavaScript/TypeScript files. No joke.

Q

Why doesn't Prettier respect my config file?

A

VS Code loads config in this order (first found wins):

  1. .prettierrc in current directory
  2. .prettierrc.js or prettier.config.js
  3. package.json "prettier" section
  4. Default settings

Debug config loading:

## See which config Prettier actually uses
npx prettier --find-config-path your-file.js

Config file isn't found: Create .prettierrc with empty {} in your project root. This forces Prettier to use that directory as the config location.

Q

How do I stop ESLint and Prettier from fighting?

A

Install the peace treaty:

npm install eslint-config-prettier --save-dev

Add to your .eslintrc:

{
  "extends": ["your-existing-config", "prettier"]
}

This disables ALL ESLint formatting rules that conflict with Prettier. Without this, you'll get warnings on every save that contradict each other.

Verify it worked:

## Should show no conflicting rules
npx eslint-config-prettier src/your-file.js

Monorepo and Configuration Nightmare Solutions

Monorepos break Prettier in creative ways. Here's how to unfuck the most common configuration disasters.

Prettier Configuration Structure

VS Code Settings Configuration

The "Works in Root, Breaks in Packages" Problem

Symptom: Formatting works in your monorepo root but fails in individual packages with `Cannot resolve module` errors.

Root cause: VS Code searches upward for config files and gets confused by multiple `package.json` files.

Solution that actually works:

  1. Create a shared Prettier config in your monorepo root:
// prettier.config.js (root of monorepo)
module.exports = {
  printWidth: 120,
  singleQuote: true,
  trailingComma: 'all',
  semi: true
};
  1. Link it from each package:
// packages/your-app/prettier.config.js
module.exports = require('../../prettier.config.js');
  1. Add to each package's .vscode/settings.json:
{
  "prettier.configPath": "./prettier.config.js",
  "prettier.requireConfig": true
}

This forces VS Code to use the local config path instead of searching randomly. See workspace configuration docs for details.

ESM Import Errors in Prettier Config

Error: Cannot use import statement outside a module in prettier.config.js

Why this happens: Prettier 3.0+ doesn't support ES6 imports in config files by default. This is a known breaking change that affects many project configurations. See Node.js ES modules guide for context.

Three solutions (pick one):

Option 1 - Use .mjs extension:

// prettier.config.mjs (NOT .js)
export default {
  printWidth: 120,
  singleQuote: true
};

Option 2 - Use CommonJS:

// prettier.config.js
module.exports = {
  printWidth: 120,
  singleQuote: true
};

Option 3 - Add "type": "module" to package.json:

{
  "type": "module",
  "devDependencies": {
    "prettier": "^3.6.0"
  }
}

Performance Hell: When Prettier Takes 2+ Minutes

Symptom: Prettier hangs on large files or takes forever to format your entire project.

Immediate fixes:

## Use the new faster CLI (Prettier 3.6+)
prettier --write . --cache --experimental-ternaries

## Skip node_modules and build folders
prettier --write . --ignore-path .gitignore

For TypeScript projects, install the Rust-powered parser:

npm install @prettier/plugin-oxc --save-dev

Add to config:

{
  "plugins": ["@prettier/plugin-oxc"],
  "printWidth": 120
}

Real performance test: I tested this on a 180k line TypeScript monorepo:

  • Before: 4 minutes 23 seconds
  • After: 18 seconds

That's not a typo. The Rust parser is stupidly fast. Similar performance improvements are seen with other Rust-based tools, and the Node.js community is adopting Rust parsers for better performance. Check Rust and JavaScript interop for technical details.

Memory Crashes on Large Files

Error: VS Code becomes unresponsive or crashes when Prettier tries to format large files (10k+ lines).

VS Code memory limit fix:

// .vscode/settings.json
{
  "prettier.enableDebugLogs": true,
  "prettier.resolveGlobalModules": false,
  "typescript.preferences.includePackageJsonAutoImports": "off"
}

Split large files or use // prettier-ignore on massive generated code blocks:

// prettier-ignore-start
const hugeGeneratedObject = {
  // 5000 lines of generated code
};
// prettier-ignore-end

Workspace vs Global Config Conflicts

Problem: Different Prettier versions between global install and project dependency cause formatting inconsistencies.

Nuclear solution:

## Remove global Prettier completely
npm uninstall -g prettier

## Use only project-local versions
npx prettier --version

## Force VS Code to use local version

Add to .vscode/settings.json:

{
  "prettier.packageManager": "npm",
  "prettier.resolveGlobalModules": false
}

This prevents VS Code from accidentally using a different Prettier version than your project expects. Version mismatches are a common source of formatting inconsistencies in team environments. See dependency management best practices and package-lock.json documentation for more.

Plugin Loading Failures

Error: Prettier plugins don't load or cause formatting to fail silently.

Debug plugin loading:

## See which plugins actually load
npx prettier --help --plugin prettier-plugin-organize-imports

Common plugin issues:

  1. Plugin version mismatch: Many plugins don't support Prettier 3.x yet
  2. Plugin load order: Some plugins conflict with each other
  3. Missing peer dependencies: Plugins require specific versions of TypeScript/ESLint

Safe plugin configuration:

{
  "plugins": ["prettier-plugin-organize-imports"],
  "pluginSearchDirs": ["node_modules"]
}

Test plugins individually - add one at a time and verify formatting works before adding the next one. Many plugin compatibility issues arise from version conflicts or incorrect installation. The Prettier plugin ecosystem requires careful dependency management and regular updates. See plugin development guide and semantic versioning for maintaining compatibility.

These monorepo and configuration nightmares are just the warm-up. Production deployments bring a whole new level of pain with CI failures, Docker issues, and team synchronization disasters.

Prettier Error Types and Solutions

Error Type

Symptoms

Common Causes

Quick Fix

Time to Fix

Red Button in VS Code

Extension shows ! icon, no formatting

Not set as default formatter

Set Prettier as default formatter in settings

2 minutes

SyntaxError: Unexpected token

Prettier refuses to format file

Broken JavaScript/TypeScript syntax

Run prettier --check filename.js to see exact error

5-15 minutes

Format on save not working

Manual format works, auto-save doesn't

Wrong file type detection

Force correct language in VS Code status bar

1 minute

Configuration not found

Uses default settings instead of custom

Config file in wrong location

Create .prettierrc in project root with {}

3 minutes

ESLint conflicts

Contradicting error messages on save

ESLint and Prettier both formatting

Install eslint-config-prettier

5 minutes

Slow performance (2+ min)

Prettier hangs or takes forever

Large files, old parser

Use --cache flag and @prettier/plugin-oxc

10 minutes

Plugin not loading

Plugin rules ignored, silent failures

Version incompatibility, wrong config

Test plugins individually, check versions

15-30 minutes

Monorepo config chaos

Works in some packages, breaks in others

Multiple config files conflict

Shared config with explicit paths

20-45 minutes

Memory crashes

VS Code becomes unresponsive

Huge files exceed memory limits

Use prettier-ignore for generated code

5 minutes

Import errors in config

Cannot use import statement

ESM syntax in config file

Use .mjs extension or CommonJS

2 minutes

CI/CD and Production Formatting Disasters

When Prettier works locally but breaks in production, CI, or for other team members - here's how to debug and fix the environment-specific failures.

CI/CD Pipeline Error

Docker Container Configuration

The "Works on My Machine" Syndrome

Scenario: Your code formats perfectly locally, but CI fails with formatting errors or team members can't get consistent formatting.

Root causes (in order of frequency):

  1. Different Prettier versions between developers
  2. Platform-specific line ending issues (Windows CRLF vs Unix LF)
  3. Node.js version differences affecting parser behavior
  4. Missing .prettierrc in CI environment

The lockdown solution (recommended by Prettier maintainers):

// package.json - pin the exact version
{
  "devDependencies": {
    "prettier": "3.6.0"
  },
  "engines": {
    "node": ">=18.0.0"
  }
}
## In CI script - fail fast on formatting issues
npm ci --ignore-scripts
npx prettier --check . --ignore-path .gitignore

## Exit code 1 if any files need formatting
if [ $? -ne 0 ]; then
  echo "Code not formatted. Run 'npm run format' locally"
  exit 1
fi

Line Ending Hell (Windows vs Mac/Linux)

Error: Files constantly show as "changed" in Git even when unchanged, or CI formatting differs from local.

Symptoms: Every line shows as modified in Git diff, Prettier formats the same file differently on different OS. This is a well-documented issue that affects cross-platform teams and Docker deployments.

The permanent fix:

  1. Set Git to handle line endings:
## Configure Git globally (run once per machine)
git config --global core.autocrlf input   # Mac/Linux
git config --global core.autocrlf true    # Windows

## Fix existing repository
git config core.autocrlf input
git rm --cached -r .
git reset --hard
  1. Add .editorconfig to project root:
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
  1. Configure Prettier for consistent line endings:
// .prettierrc
{
  "endOfLine": "lf",
  "insertFinalNewline": true
}

Dockerfile and Container Formatting Issues

Problem: Prettier works on host machine but fails inside Docker containers.

Common container issues (Docker troubleshooting guide):

Production-ready Dockerfile:

## Use exact Node version (not "latest")
FROM node:18.17.0-alpine

## Install specific Prettier version globally for consistency
RUN npm install -g prettier@3.6.0

## Set memory limit for large codebases  
ENV NODE_OPTIONS="--max-old-space-size=4096"

WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production

## Add non-root user to avoid permission issues
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
USER nextjs

COPY --chown=nextjs:nodejs . .

Pre-commit Hook Failures

Issue: lint-staged or husky pre-commit hooks fail inconsistently or cause commits to hang.

Debugging pre-commit issues:

## Test pre-commit hook manually
npx lint-staged --debug

## See exactly what files are being processed
npx lint-staged --verbose

## Skip hooks temporarily for debugging
git commit --no-verify -m "test commit"

Bulletproof pre-commit configuration:

// package.json
{
  "lint-staged": {
    "*.{js,ts,jsx,tsx}": [
      "prettier --write --ignore-unknown",
      "git add"
    ],
    "*.{css,scss,md,json}": [
      "prettier --write --ignore-unknown",
      "git add"  
    ]
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged --allow-empty"
    }
  }
}

The --ignore-unknown flag prevents Prettier from choking on file types it doesn't recognize.

Memory and Timeout Issues in CI

Error: CI builds timeout or run out of memory when formatting large codebases.

Symptoms:

  • CI jobs killed after 10+ minutes
  • "JavaScript heap out of memory" errors
  • Random formatting failures on large files

CI optimization strategies:

## GitHub Actions example
- name: Format check with optimizations
  run: |
    # Increase Node.js memory limit
    export NODE_OPTIONS="--max-old-space-size=8192"
    
    # Use cache to speed up subsequent runs
    npx prettier --check . --cache --ignore-path .gitignore
    
    # Parallel processing for huge repos
    find . -name "*.js" -o -name "*.ts" | head -1000 | xargs -P 4 npx prettier --check

Split large formatting tasks:

## Instead of formatting everything at once
prettier --write . --ignore-path .gitignore

## Process in chunks to avoid memory issues
find src -name "*.ts" | head -100 | xargs prettier --write
find src -name "*.ts" | tail -n +101 | head -100 | xargs prettier --write

Version Lockfile Conflicts

Problem: Team members have different formatting because lockfiles (package-lock.json, yarn.lock) specify different Prettier versions.

Symptoms: Same config file produces different output on different machines.

Solution - Version discipline:

  1. Commit your lockfile - never add package-lock.json to .gitignore
  2. Use npm ci in CI - not npm install
  3. Audit Prettier version regularly:
## Check what version is actually installed
npm list prettier

## Check if prettier is installed multiple times (common issue)
npm ls prettier --depth=0

## Force specific version installation
rm -rf node_modules package-lock.json
npm install prettier@3.6.0 --save-dev --save-exact
npm ci

Lockfile validation in CI:

## Fail CI if lockfile is out of date
npm ci
npm audit fix --dry-run
if [ -n "$(git diff --name-only)" ]; then
  echo "Lockfile is out of date. Run 'npm install' locally."
  exit 1
fi

This catches the common issue where developers run npm install with different versions and create conflicting lockfiles. Lockfile consistency is critical for reproducible builds and avoiding dependency hell. Security audits and dependency management are essential for production deployments.

Advanced Troubleshooting Questions

Q

How do I debug what config file Prettier is actually using?

A

Use the Prettier CLI to trace config loading:

## See the exact config path and values
npx prettier --find-config-path src/MyComponent.js

## Debug config resolution (shows search path)
npx prettier --config-precedence prefer-file --check src/

VS Code config debugging:

  1. Open Command Palette (Cmd+Shift+P)
  2. Run "Prettier: Show Output"
  3. Save a file to trigger formatting
  4. Check output for config loading messages

Common config gotchas:

  • .prettierrc.js overrides .prettierrc.json even if JSON is newer
  • VS Code caches config - restart after config changes
  • Monorepos load config from closest parent directory
Q

Why does Prettier format differently on different files?

A

File-specific overrides in config:

// .prettierrc
{
  "semi": true,
  "overrides": [
    {
      "files": "*.json",
      "options": {
        "semi": false
      }
    }
  ]
}

Language parsing differences: TypeScript files get different treatment than JavaScript for generics and decorators.

Plugin interference: Some plugins only apply to specific file patterns.

Debug file-specific formatting:

## Test one file at a time
npx prettier --check src/Component.tsx --debug-check

## Compare parsed AST between files
npx prettier --debug-print-doc src/file1.js > file1.ast
npx prettier --debug-print-doc src/file2.js > file2.ast
diff file1.ast file2.ast
Q

How do I make Prettier work with my custom file extension?

A

Associate custom extensions with existing parsers:

// .prettierrc
{
  "overrides": [
    {
      "files": "*.myext",
      "options": {
        "parser": "typescript"
      }
    }
  ]
}

VS Code file association:

// .vscode/settings.json
{
  "files.associations": {
    "*.myext": "typescript",
    "*.config": "json"
  }
}

Common custom extensions:

  • .mjs"parser": "babel"
  • .cjs"parser": "babel"
  • .vue → requires prettier-plugin-vue
  • .svelte → requires prettier-plugin-svelte
Q

Why does Prettier work in terminal but not VS Code?

A

PATH differences between terminal and VS Code:

## Check which Prettier VS Code uses
code --version
echo $PATH

## VS Code often uses system PATH, not shell PATH
which prettier

Force VS Code to use project Prettier:

// .vscode/settings.json
{
  "prettier.resolveGlobalModules": false,
  "prettier.packageManager": "npm"
}

Reload VS Code window after PATH changes:

  • Command Palette → "Developer: Reload Window"
Q

How do I fix "Prettier requires a valid parser" errors?

A

Missing parser for file type:

## Install required parsers
npm install @prettier/plugin-php --save-dev  # PHP
npm install prettier-plugin-java --save-dev  # Java

Explicitly specify parser:

## Force parser for ambiguous files
npx prettier --write --parser typescript src/ambiguous.txt

Config with parser mapping:

{
  "overrides": [
    {
      "files": "*.txt",
      "options": {
        "parser": "markdown"
      }
    }
  ]
}
Q

How do I disable Prettier for specific sections without comments?

A

Directory-level ignoring:

// .prettierignore
build/
dist/
*.min.js
**/node_modules/
**/*.d.ts

File pattern ignoring:

## Ignore all generated files
**/*generated*
src/api/*.gen.ts

Programmatic ignoring:

// In prettier.config.js
module.exports = {
  printWidth: 100,
  // Skip formatting for files matching these patterns  
  ignore: [
    "src/legacy/**/*",
    "**/*.generated.js"
  ]
}
Q

How do I migrate a large codebase without breaking everything?

A

Incremental formatting strategy:

## Format only files modified in last 30 days
git log --since="30 days ago" --name-only --pretty=format: | sort | uniq | xargs prettier --write

## Format only files in current PR
git diff --name-only main..HEAD | xargs prettier --write

Progressive formatting with Git hooks:

// package.json
{
  "lint-staged": {
    "*.{js,ts}": [
      "prettier --write",
      "git add"
    ]
  }
}

Create formatting PRs by directory:

## Format one directory at a time
prettier --write src/components/ 
git add -A && git commit -m "format: components directory"

prettier --write src/utils/
git add -A && git commit -m "format: utils directory"

This creates reviewable PRs instead of massive 50k-line formatting changes.

Related Tools & Recommendations

review
Similar content

ESLint & Prettier: Performance, Usability & Alternatives

After 7 years of dominance, the cracks are showing

ESLint
/review/eslint-prettier-setup/performance-usability-review
100%
news
Similar content

VS Code 1.103 Fixes MCP Server Restart Hell for AI Developers

Microsoft just solved one of the most annoying problems in AI-powered development - manually restarting MCP servers every damn time

Technology News Aggregation
/news/2025-08-26/vscode-mcp-auto-start
67%
review
Similar content

Zed vs VS Code vs Cursor: Performance Benchmark & 30-Day Review

30 Days of Actually Using These Things - Here's What Actually Matters

Zed
/review/zed-vs-vscode-vs-cursor/performance-benchmark-review
67%
tool
Similar content

Prettier Plugin Conflicts: Debugging & Configuration Guide

When your Prettier plugins hate each other more than your ex-coworkers

Prettier
/tool/prettier/plugin-troubleshooting
67%
tool
Similar content

Prettier: Opinionated Code Formatter Overview & Setup Guide

Learn about Prettier, the opinionated code formatter. This overview covers its unique features, installation, setup, extensive language support, and answers com

Prettier
/tool/prettier/overview
62%
tool
Similar content

Debugging AI Coding Assistant Failures: Copilot, Cursor & More

Your AI assistant just crashed VS Code again? Welcome to the club - here's how to actually fix it

GitHub Copilot
/tool/ai-coding-assistants/debugging-production-failures
56%
tool
Recommended

ESLint - Find and Fix Problems in Your JavaScript Code

The pluggable linting utility for JavaScript and JSX

eslint
/tool/eslint/overview
47%
tool
Similar content

GitHub Copilot Performance: Troubleshooting & Optimization

Reality check on performance - Why VS Code kicks the shit out of JetBrains for AI suggestions

GitHub Copilot
/tool/github-copilot/performance-troubleshooting
43%
tool
Similar content

VS Code Team Collaboration: Master Workspaces & Remote Dev

How to wrangle multi-project chaos, remote development disasters, and team configuration nightmares without losing your sanity

Visual Studio Code
/tool/visual-studio-code/workspace-team-collaboration
40%
tool
Similar content

GitHub Codespaces - Cloud Dev Environments That Actually Work

Discover GitHub Codespaces: cloud-based VS Code dev environments with instant project setup. Understand its core features, benefits, and a realistic look at pri

GitHub Codespaces
/tool/github-codespaces/overview
40%
tool
Similar content

Thunder Client Migration Guide - Escape the Paywall

Complete step-by-step guide to migrating from Thunder Client's paywalled collections to better alternatives

Thunder Client
/tool/thunder-client/migration-guide
39%
tool
Similar content

React Production Debugging: Fix App Crashes & White Screens

Five ways React apps crash in production that'll make you question your life choices.

React
/tool/react/debugging-production-issues
38%
tool
Similar content

Thunder Client Paywall: VS Code API Testing & Pricing Changes

What started as a free Postman alternative for VS Code developers got paywalled in late 2024

Thunder Client
/tool/thunder-client/overview
36%
tool
Similar content

TaxBit Enterprise Production Troubleshooting: Debug & Fix Issues

Real errors, working fixes, and why your monitoring needs to catch these before 3AM calls

TaxBit Enterprise
/tool/taxbit-enterprise/production-troubleshooting
35%
compare
Similar content

Enterprise Editor Deployment: Zed vs VS Code vs Cursor Review

Zed vs VS Code vs Cursor: Why Your Next Editor Rollout Will Be a Disaster

Zed
/compare/zed/visual-studio-code/cursor/enterprise-deployment-showdown
34%
compare
Similar content

VS Code vs Zed vs Cursor: Best AI Editor for Developers?

VS Code is slow as hell, Zed is missing stuff you need, and Cursor costs money but actually works

Visual Studio Code
/compare/visual-studio-code/zed/cursor/ai-editor-comparison-2025
34%
tool
Similar content

Arbitrum Production Debugging: Fix Gas & WASM Errors in Live Dapps

Real debugging for developers who've been burned by production failures

Arbitrum SDK
/tool/arbitrum-development-tools/production-debugging-guide
32%
tool
Similar content

Cursor AI: VS Code with Smart AI for Developers

It's basically VS Code with actually smart AI baked in. Works pretty well if you write code for a living.

Cursor
/tool/cursor/overview
32%
tool
Similar content

Zed Editor Overview: Fast, Rust-Powered Code Editor for macOS

Explore Zed Editor's performance, Rust architecture, and honest platform support. Understand what makes it different from VS Code and address common migration a

Zed
/tool/zed/overview
32%
tool
Similar content

Bolt.new: VS Code in Browser for AI Full-Stack App Dev

Build full-stack apps by talking to AI - no Docker hell, no local setup

Bolt.new
/tool/bolt-new/overview
32%

Recommendations combine user behavior, content similarity, research intelligence, and SEO optimization