How to fix Prettier Extension not working in VS Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
5 min

banner

# Make sure Prettier is selected as your Default formatter

The first thing you should check is that Prettier is selected as your default formatter.

  1. Press:
  • Ctrl + Shift + P on Windows and Linux
  • Command + Shift + P on macOS
  1. Type preferences open settings and select Preferences: Open Settings (UI).
Note that you can also use the Ctrl + , (or Cmd + , on macOS) keyboard shortcut to open the settings menu.

preferences-open-settings-ui

  1. Type default formatter and in the Editor: Default Formatter, make sure to select Prettier - Code formatter as your default formatter.

set prettier as default formatter

Make sure that all checkboxes of languages are checked as shown in the following screenshot.

make sure all languages are ticked

If you can't find the Settings menu, click on:

  1. File -> Preferences -> Settings on Windows and Linux.
  2. Code -> Preferences -> Settings on macOS.
Note that you might have to press Alt to show the top menu on Windows and Linux.

open settings

# Make sure Format on Save is enabled

Make sure the Format on Save setting is enabled:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
  1. Type preferences open settings and select Preferences: Open Settings (UI).
Note that you can also use the Ctrl + , (or Cmd + , on macOS) keyboard shortcut to open the settings menu.

enable format on save setting

# Click on the prettier icon in the Status Bar

The next thing you should try is to click on the prettier icon in the Status Bar at the bottom right corner of the screen.

click-on-prettier-icon-in-status-bar

When you click on the icon, the OUTPUT tag gets focused.

If there are any issues with your Prettier installation or configuration, they are shown in the OUTPUT tab.

prettier output tab

If you can't see the prettier button in the Status Bar, right-click on the Status Bar at the bottom and make sure the Prettier option is ticked.

right click on status bar to show prettier

# Try using the Format Document action

Another thing you should try is to use the Format Document action from the Command Palette:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Format Document and select the option.

format document

If you haven't installed a formatter for the specific file, you will get prompted.

prompt-to-install-formatter

# Try setting Prettier as the formatter for the specific file

Another thing you can try is to set Prettier as the formatter for the specific file and all other files with the extension.

  1. Open and focus a specific file (e.g. a .js file).

  2. Press:

  • Ctrl + Shift + P on Windows and Linux
  • Command + Shift + P on macOS
Note: you can also press F1 to open the Command Palette.
  1. Type Format Document With and select the option.

format document with

  1. Click on Configure Default Formatter....

configure default formatter

  1. Click on Prettier - Code formatter.

select prettier

# Make sure the Prettier extension is installed and enabled

Make sure the Prettier extension is installed and enabled:

  1. Click on Extensions in the left sidebar.
  • You can also open the Extensions menu by pressing:
    • Ctrl + Shift + X on Windows or Linux
    • Command + Shift + X on macOS
  1. Type Prettier and make sure the extension is installed and enabled.

make sure prettier is installed

Also, make sure to install the original Prettier extension that was developed by the Prettier organization.

# Disable the extension and reenable it

The next thing you should try is to disable the extension and reenable it.

Once you click on the extension in the left sidebar:

  1. Click on the Disable button to disable the extension.

disable extension

You might get prompted to reload VS Code after disabling the extension.

  1. After you reload VS Code, click on the Enable button to reenable the extension.

reload and enable extension

# Installing the Prettier module locally

Another thing you can try is to install the prettier module locally.

Open your terminal in your project's root directory (where your package.json file is) and run the following command.

shell
# in case you don't have a package.json file yet npm init -y npm install prettier -D --save-exact

The command installs the prettier module locally.

If the package is installed locally, the extension will use your project's local version.

Otherwise, the version that is bundled with the extension will be used.

Make sure you also have your other modules installed.

shell
# for NPM npm install # for YARN yarn install

# Restart VS Code

Another thing you can try is to restart VS Code:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux
  • Command + Shift + P on macOS
Note: you can also press F1 to open the Command Palette.
  1. Type reload window and select Developer: Reload Window.

reload window

# Make sure Format on Save Mode is set to File

Make sure Format on Save Mode is set to file:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
  1. Type preferences open settings and select Preferences: Open Settings (UI).
Note that you can also use the Ctrl + , (or Cmd + , on macOS) keyboard shortcut to open the settings menu.

preferences-open-settings-ui

  1. Type format on save and make sure Editor: Format on Save Mode is set to file.

set format on save mode to file

# Having a local settings.json file with incorrect config

Make sure you don't have a local .vscode/settings.json file where you've set editor.formatOnSave to false.

For example, the following config would prevent you from formatting your code on save.

.vscode/settings.json
{ "editor.formatOnSave": false }

Even if you have format on save enabled globally, the local config in the .vscode directory would override the global setting.

Make sure you haven't set formatOnSave to false locally in .vscode/settings.json.

You might also have the setting in your package.json file which also takes precedence over your global config.

# Try reinstalling Prettier

Another thing you can try is to reinstall the Prettier extension:

  1. Click on Extensions in the left sidebar.
  • You can also open the Extensions menu by pressing:
    • Ctrl + Shift + X on Windows or Linux.
    • Command + Shift + X on macOS.
  1. Type Prettier, click on the cogwheel and select Uninstall.

uninstall prettier extension

  1. After you uninstall the extension, you will be prompted to reload VS Code.
  2. Reload the IDE and click on the Install button to install the extension.

reload and install prettier

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.