Programming & Coding How-TosTechnology

Why Is Prettier Not Formatting My Files in VS Code? Every Cause Fixed

Admin
Why Is Prettier Not Formatting My Files in VS Code? Every Cause Fixed

You installed the Prettier extension, you press the format shortcut, and… nothing happens. Or you save a file and it stays exactly as messy as before. Few VS Code problems are this frustrating, because everything looks installed and enabled. In reality, Prettier almost always has a specific reason for refusing to work: it is not the default formatter, its config file has an error, or the file you are editing is one it deliberately ignores.

This guide works through the causes in the order you are most likely to hit them, with a quick check for each, so you can find your reason fast and get automatic formatting back.

Quick Answer

Prettier usually fails to format because it is not set as the default formatter for that language, because a .prettierrc or package.json config contains an error, or because the file is listed in .prettierignore. Set the default formatter to Prettier, check the Prettier output panel for error messages, and confirm the file type is one Prettier supports. One of those three fixes solves the problem in nearly every case.

Cause 1: Prettier Is Not the Default Formatter

Installing the extension does not make it the formatter VS Code uses. If another formatter, or none, is set as default, your shortcut and format on save will use that instead, and Prettier sits idle. Fix it directly:

  1. Open a file of the type that will not format.
  2. Right-click in the editor and choose Format Document With…
  3. If Prettier is not the entry marked as default, choose Configure Default Formatter and select Prettier – Code formatter.
  4. Try Format Document again.

Remember that defaults can be set per language. Prettier might be the global default but overridden for, say, JSON or HTML by a [json] block in settings. The complete setup sequence is covered in our guide to formatting code automatically on save in VS Code with Prettier.

Cause 2: An Error in the Prettier Config File

Prettier reads its options from a .prettierrc file, a prettier.config.js, or a "prettier" key in package.json. A single typo, a trailing comma in JSON, or an option name from an old version makes the whole config invalid, and Prettier refuses to format anything rather than guess. To test this quickly:

  1. Rename the config file temporarily, or empty the "prettier" key in package.json.
  2. Try formatting again. If it works now, the config was the problem.
  3. Rebuild the config option by option, checking names against the official Prettier configuration documentation.

Cause 3: The File Is Being Ignored

Prettier skips files listed in a .prettierignore file, and it also skips files inside node_modules and other generated folders by design. Open .prettierignore in your project root and check whether your file, its folder, or a broad pattern like *.min.js or dist covers it. Also confirm the file is saved on disk with a proper name; Prettier cannot format an untitled, never-saved editor tab in some setups.

Cause 4: The Language Is Not Supported

Prettier formats JavaScript, TypeScript, HTML, CSS, JSON, Markdown, YAML and a good list of others, but not every language on earth. Python, Java and C++ need plugins or entirely different formatters. Check the language mode in the bottom-right corner of VS Code too: a JavaScript file accidentally set to a different language mode will not be offered to Prettier at all. Click the language name and set it correctly.

Cause 5: The Extension Needs a Project Version or a Restart

Sometimes the extension itself is in a bad state. Open the Output panel and choose Prettier from the dropdown to read its log; it prints the exact reason for failures, including config errors and version problems. If the log mentions a missing module in a project that pins its own Prettier, run npm install so the local copy exists. A plain editor restart also clears many one-off glitches, and the extension page on Prettier’s editor integration lists what the extension logs mean.

Cause 6: Format On Save Is On, but It Times Out

If manual formatting works but saving does not format, the feature is either off or running out of time. Confirm editor.formatOnSave is true in settings, then consider editor.formatOnSaveTimeout: very large files can exceed the default limit, so formatting is silently skipped. Raising the timeout, or formatting huge files manually in smaller pieces, resolves it.

Common Mistakes to Avoid

  • Installing a lookalike extension. Several extensions borrow Prettier’s name. The official one is Prettier – Code formatter by Prettier.
  • Checking only global settings. Workspace and language-specific settings override global ones, so search all three levels.
  • Assuming a silent failure means no information. The Prettier output channel almost always records the reason.
  • Reinstalling everything first. The cause is nearly always configuration, so check settings before reaching for reinstalls.

Cause 7: Another Save Action Is Undoing or Blocking It

Sometimes Prettier runs perfectly, but the file still ends up unformatted because something else acts on save after it. ESLint with auto-fix enabled can rewrite the same file using different rules, and a second formatter extension can do the same. The result looks like Prettier did nothing, or like the style flip-flops between saves. To test this, disable other formatters temporarily, save, and watch the result. The standard resolution is to let Prettier own layout entirely and configure other tools to skip formatting, for instance by using eslint-config-prettier in JavaScript projects so the two never fight.

A Two-Minute Diagnostic Routine

When you are not sure where to start, run through this fixed routine instead of guessing:

  1. Open a small JavaScript file and run Format Document With… to see which formatter is default for that language.
  2. Open the Output panel, select Prettier, and try formatting again while watching the log appear.
  3. Rename any .prettierrc file for ten seconds and retry, to rule the config in or out.
  4. Check .prettierignore for your file’s name or folder.
  5. Confirm the language mode in the status bar matches the file.

One of these five steps exposes the cause almost every time, and each takes seconds. Keeping the routine in this order stops you from reinstalling extensions when the real problem was a one-line config mistake.

It also helps to remember that Prettier formats on demand per file, not for the whole project at once. If only one or two files misbehave while the rest format correctly, that pattern itself is a clue: the problem is local to those files, which points straight at the ignore list, the language mode or a file-specific quirk rather than your global setup.

Conclusion

When Prettier will not format, it is giving you silent feedback about configuration, not failing at random. Work through the short list: default formatter, valid config, ignore files, supported language, extension log, and save timeout. Most people find their answer in the first two checks, and once Fixed, formatting quietly works on every file again.

Frequently Asked Questions

How do I know which formatter VS Code is using?

Right-click in the editor and choose Format Document With… The formatter marked as default is the one in use. You can change it from the same menu via Configure Default Formatter.

Where does Prettier print its errors?

Open View > Output and select Prettier in the dropdown on the right of the Output panel. Config problems, version issues and skipped files are all logged there with details.

Why does Prettier format some files but not others in the same project?

Usually an ignore pattern covers the stubborn files, or they are a language Prettier does not support, or that language has a different default formatter set. Compare the working and broken files on those three points.

Does Prettier need a config file to work?

No. With no config file, Prettier uses its built-in defaults and formats happily. A config file is only needed when you want to change options like quote style or tab width, and a broken config is worse than none.

Will Prettier format code inside HTML files?

Yes. Prettier understands embedded CSS and JavaScript inside HTML and formats the whole document, which is one reason it is popular for small web projects.

Admin

Passionate about the intersection of style and storytelling. I simplify fashion trends and industry news into easy-to-follow advice, helping you stay stylish and informed in the fast-paced world of fashion.

Leave a Reply

Your email address will not be published. Required fields are marked *