Why does Prettier not format code in VS Code?
How I've sorted it after having super huge frustrations with Prettier stopping working in VSCode.
- Select
VS Code
->View
->Command Palette
, and type:Format Document With
- Then
Configure Default Formatter...
and then choosePrettier - Code formatter
.
This sorted the problem for me magically.
Depending on your case this might help you...
Vs Code, why Prettier is not formatting code
There can be two issue why prettier is not formatting your code.
1. You have multiple formatter available
- Press CtrlShiftP and type "Format Document".
- if you have multiple fomatter available you will be ask to choose a default one.
- Select prettier to make it your default fomatter.
2. You don't have config file for prettier
- In your project directory you need to have a prettierrc file which can be used to configure prettier. So create a new file with name
.prettierrc
and add some settings. For more information about .prettierrc file see this link - If you don't want to have this file and use default settings for prettier, go to settings and search for prettier require config and disable this setting.
Why Prettier code formatter stopped formatting in VS Code?
Follow theses steps and I think it is gonna work :
- Install prettier from the extensions store :
- Go and edit
settings.json
file and past in the lines below. You can findsettings.json
this way :
- On Windows :
F1
orCtrl
+
Shift
+
P
, then typeopen settings
and chooseOpen Settings (JSON)
- On MacOS :
Shift
+
CMD
+
P
, then the same steps as Windows
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
}
Restart VS Code.
Make sure you have the same checks icons at the bottom right corner of VS Code when you open a file that Prettier handles (.html, .css, .js, etc) :
Prettier doesn't format my code in Visual Studio on Next.js
- Make sure that Prettier is enabled as your default formatter. See here for details on how to do that.
- Make sure that Format On Save is enabled, or that you're calling the formatting option manually.
- Resolve all errors, then try again. Personally, Prettier refuses to format if there are any errors. Warnings are fine, but only if all errors are resolved does Prettier perform formatting, on my projects.
Related Topics
Merge Two Json/Javascript Arrays in to One Array
Extract Part of Url With Regex
How to Add Spaces to for Loop Output in JavaScript
How to Send a Http Delete Request from Browser
New Line in Paragraph When Enter Is Pressed in Textarea
Javascript Add Class Active When Click a Link After Load Another Page
Syntaxerror: Cannot Use Import Statement Outside a Module
Barcode Scanner for Mobile Phone for Website in Form
Changing Svg Image Color With JavaScript
Can You Combine Multiple Images into a Single One Using JavaScript
Jquery Change Event Called Two Times
Why Is It a Bad Practice to Return Generated HTML Instead of Json or Is It
Check If Value Select2 Is Null
Multi Select Drop Down With Checkbox