Follow these steps:
- CTRL + SHIFT + P
- Format Document (in pop-up bar)
- Select
Format Document - Select
Configure Default Formatter... - Select
Prettier - Code formatter
Done!
Answer from Goku on Stack OverflowFollow these steps:
- CTRL + SHIFT + P
- Format Document (in pop-up bar)
- Select
Format Document - Select
Configure Default Formatter... - Select
Prettier - Code formatter
Done!
In VSCode settings, search for "Editor: Default Formatter", set it to esbenp.prettier-vscode and restart VSCode.
Videos
steps to follow (using prettierenter image description here):
- Click on the right corner text 'JavaScript React'
- select configure 'JavaScript React' language based settings
- add this snippet in the file
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.formatOnSave": true
All set to run perfect!
Go to settings and type default formatter which is null at the beginning. Change it to esbenp.prettier-vscode. This is what is working for me. Hope it does for you.
In VSCode, hit CTRL + SHIFT + P, write Preferences: Open User Settings (JSON) and hit enter, it will open up your settings.json:
Make sure prettier is your default formatter:
"editor.defaultFormatter": "esbenp.prettier-vscode"
you can set it for specific languages e.g: for typescript:
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
TLDR; Settings > Prettier Require Config: false / unchecked
I tried these and it still wasn't working. I noticed that at the bottom of my VS Code my Prettier wasn't showing a checkmark next to it. Clicked on "Prettier" at the bottom of the screen and it said it was skipping the file because there was not a require config set to true.
Solution was in this thread here: Prettier extension is not working in vs code Require config set to true
Hello, I really need help, prettier just stopped working with react for no reason, as you can see it works with json files, but not react. What could be the reason? here is my settings.json:
{
"editor.bracketPairColorization.enabled": true,
"editor.accessibilitySupport": "off",
"editor.formatOnSave": true,
"typescript.updateImportsOnFileMove.enabled": "always",
"editor.inlineSuggest.enabled": true,
"github.copilot.enable": {
"*": true,
"yaml": false,
"plaintext": true,
"markdown": true
},
"window.zoomLevel": -2,
"github.copilot.advanced": {},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnPaste": true,
"[typescriptreact]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
}How can it suddenly stop working?
I'm having a lot of trouble with prettier formatting my .tsx files in VSCode. I've tried many things to get prettier to work. I've disabled typescript formatting and set the default to prettier, but it didn't work. It's just not happening. I've settled for formatting everything myself, but I'm prettier-spoiled and I want prettier to format my .tsx files too. How have you (people who are savvier than I) gotten .tsx files to auto format with prettier using VSCode?
eslint prettier plugin works pretty well for me.
I followed this guide: https://dev.to/robertcoopercode/using-eslint-and-prettier-in-a-typescript-project-53jb
It also covers how to setup VSCode.
Do you have "editor.formatOnSave" set to true in your preferences?
That was the one thing I missed when I was setting it up.