Prettier doesn't format .tsx file
Solution 1
Edit setting with following in settings.json
of VScode
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
Solution 2
Expanding on iNeelPatel's answer, I had to add two lines to VSCode JSON settings:
"[typescript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
"[typescriptreact]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }
Solution 3
This will give perfect solution
"Same thing happened to me just now. I set prettier as the Default Formatter in Settings and it started working again. My Default Formatter was null."
https://github.com/microsoft/vscode/issues/108447#issuecomment-706642248
Solution 4
An easy UI alternative to what has been proposed already:
- Search for "default formatter" in your vscode settings.
- Click on "Text Editor" and set the default formatter to "Prettier - Code formatter".
- Enjoy.
Solution 5
Create a .vscode
folder at the root of your project. In the .vscode
folder, create the settings.json
file, and in it, write this section:
{
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
Don't forget to add .vscode
in the .gitignore
file.
Related videos on Youtube
S. Hesam
I love learning. I used to study physics and I am very interested in physics. I was using the C programming language to simulate the interaction of lasers and electrons, and I wrote various programs for my research. When I was programming for the numerical resolution of physics issues, I realized that I deeply loved programming, So I decided to become a programmer.
Updated on July 09, 2022Comments
-
S. Hesam almost 2 years
I've used the Prettier extension in the visual studio code editor for a long time, but recently I am writing to React with Typescript. So I need to configure for Prettier to format .tsx files.
-
Emile Bergeron almost 4 yearsDo you have
prettier
as a dependency of this project?
-
-
smbergin79 almost 3 yearsYou just made my day!
-
Dylan Kapp over 2 yearsIn case you are wondering how to access settings.json -> stackoverflow.com/a/65909052/5888998
-
Uche Azinge over 2 yearsTo open settings follow these steps: Shift + CMD + P, Type "settings", Click on "preferences: open settings(JSON)"
-
chichi over 2 yearsTHANK YOU!!!!!!
-
VINIT CHURI about 2 yearsworked for me 👍