简体   繁体   中英

Why Prettier code formatter stopped formatting in VS Code?

I am trying to format the code but the prettier isn't working fine with VS code. I also tried to reinstall it but the same problem occurs. I am not able to format my html css code with prettier. You can also see the screenshot where the code is not formatted after saving the code.

在此处输入图像描述

Follow theses steps and I think it is gonna work:

  1. Install prettier from the extensions store:

在此处输入图像描述

  1. Go to and edit settings.json file and past in the lines below. You can find settings.json by doing so:
  • On Windows: F1 or Ctrl + Shift + P , then type open settings and choose Open Settings (JSON)
  • On MacOS: Shift + CMD + P , then the same steps as Windows
{ 

  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  
}
  1. Restart VS Code.

If you apply the steps mentioned in the below answer (by yousoumar), and still got no solution, then there may be an error that prettier is catching. You can always check for that by clicking on the bottom right corner, where it says prettier (tho if there are two small check marks, then there's probably no errors at all)

Edit settings.json page

  • Windows: Ctrl + Shift + P
  • On MacOS: Shift + CMD + P

I had to add the following:

{
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[jsonc]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[json]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[css]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[scss]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM