Prettier does nothing when you format a .tsx file in VS Code
Format Document does nothing on a .tsx fileShort answer
When Prettier ignores .tsx files, VS Code is usually using another formatter for that language, the file is excluded, or a setting blocks it. Set esbenp.prettier-vscode as the default formatter for typescriptreact in its own block, then check .prettierignore, prettier.requireConfig and format on save.
Fix it fast
1Find out which cause you have
Open the Prettier output from the status bar while the .tsx file is active. Check it for error messages.
// Click "Prettier" in the status bar (bottom right) with the .tsx file open2Match what you see, then jump to its fix
- 1
Format Document asks which formatter to use, or another formatter runsPrettier is not the default formatter for TypeScript React filesFix - 2
Manual Format Document works, saving does not formatFormat on save is not on for that languageFix - 3
The file matches a pattern in .prettierignore, or sits in node_modulesThe file is ignored by .prettierignoreFix - 4
Formatting works in projects that have a .prettierrc and stays silent in this oneprettier.requireConfig is true and no config file existsFix
- 1
What does the error look like?
Format Document does nothing on a .tsx file
Cause 1 of 4
Prettier is not the default formatter for TypeScript React files
1Check
VS Code does not accept combined language keys for editor.defaultFormatter, so a block such as [typescript][typescriptreact] is ignored.
grep -n -B1 -A3 "defaultFormatter" .vscode/settings.json2Fix
Give each language its own block.
{
"[typescript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
"[typescriptreact]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }
}3Verify
Run Format Document on the .tsx file; no formatter picker appears.
// Command Palette
Format DocumentConfirmed by github.com
Cause 2 of 4
Format on save is not on for that language
1Check
The extension follows editor.formatOnSave, which can be set per language.
grep -n "formatOnSave" .vscode/settings.json2Fix
Turn it on for TypeScript React.
{
"[typescriptreact]": { "editor.formatOnSave": true }
}3Verify
Add a badly spaced line to a .tsx file and save.
// the line is reformatted on saveConfirmed by github.com
Cause 3 of 4
The file is ignored by .prettierignore
1Check
The extension reads .prettierignore by default, and files in node_modules are ignored.
cat .prettierignore2Fix
Remove the pattern that matches your file. To format an ignored file once, use the Format Document (Forced) command.
// Command Palette
Format Document (Forced)3Verify
Format the file normally after editing the ignore file.
npx prettier --check src/App.tsxConfirmed by github.com
Cause 4 of 4
prettier.requireConfig is true and no config file exists
1Check
With requireConfig set to true, Prettier formats a file only if a config file exists.
grep -rn "requireConfig" .vscode/settings.json; ls .prettierrc*2Fix
Create a config file, or set the option to false.
{
"prettier.requireConfig": false
}3Verify
Run Format Document on the .tsx file.
// Command Palette
Format DocumentConfirmed by github.com
How do I stop it coming back?
- Commit .vscode/settings.json with one defaultFormatter block per language the project uses.
- Run prettier --check in CI, so formatting does not depend on every editor being set up.
- Add a .prettierrc to the repo so requireConfig never silently disables the extension.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Related fixes
Web apps
tsconfig rejects allowImportingTsExtensions
An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly
allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.
2 causes, each with a fixWeb apps
AuthUserPoolException: Auth UserPool not configured in a Next.js app
Auth UserPool not configured
The error means an Amplify Auth call ran before Amplify.configure did.
3 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Apollo Client is blocked by CORS when the GraphQL server runs on AWS Lambda
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Apollo Server does not set CORS for you when it runs behind a framework or integration, and on Lambda that layer is API Gateway.
5 causes, each with a fixWeb apps
A POST to a Google Apps Script web app returns 405 or a CORS error
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Apps Script web apps run doPost for POST and doGet for GET, and the Apps Script guides describe no other entry points.
3 causes, each with a fix