Same for me, I managed to solve it with:
{
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.formatOnType": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[html]": {
"editor.defaultFormatter": "vscode.html-language-features"
}
}
This allowed me to use prettier globally and use built in html formatter for html. Also allowed the formatting to happen on save and while typing.
The part responsible for Prettier formatting html:
"[html]": {
"editor.defaultFormatter": "vscode.html-language-features"
},
To open type
Ctrl+Shift+P, then type open user/workspace settings JSON in the command line.
Same for me, I managed to solve it with:
{
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.formatOnType": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[html]": {
"editor.defaultFormatter": "vscode.html-language-features"
}
}
This allowed me to use prettier globally and use built in html formatter for html. Also allowed the formatting to happen on save and while typing.
The part responsible for Prettier formatting html:
"[html]": {
"editor.defaultFormatter": "vscode.html-language-features"
},
To open type
Ctrl+Shift+P, then type open user/workspace settings JSON in the command line.
I got the same issue, the cause can be updating the VS Code. fixed it by setting the Default Formatter of Text Editor
Go to Settings (Ctrl+, for windows), search for 'Default Formatter'
Set the formatter in dropdown (esbenp.prettier-vscode) for prettier. this can change if you are using any other formatter.
Prettier not used on HTML even though its the default formatter
Prettier extension not working on HTML files
Prettier-VSCode doesn't format selections in HTML documents
Speed-up your Prettier formatting using prettierd
If you want REALLY fast JS/TS/JSON/Markdown formatting then use the Deno language server: https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#denols
It is written in Rust, and the formatting is built into the Deno executable using a clone of Prettier https://dprint.dev/. You can use it as your main language server for web based JS/TS as well as Deno specific code.
(I recommend adding lint = true, now you have all the eslint/ts-eslint default lints included: https://deno.land/manual/tools/linter)
Put this on the top of files that give you errors:
/// <reference no-default-lib="true"/> /// <reference lib="dom" /> /// <reference lib="deno.ns" /> /// <reference lib="esnext" />
By default the Deno LSP thinks it is Deno code with no DOM or APIs that are not Deno specific.
Imports for ts must include the .ts extension, I use esbuild to then create the bundle. You can use NPM and the CLI to install esbuild, or now it just got Deno support! https://github.com/evanw/esbuild/releases/tag/v0.11.11
How do I install Prettier in VSCode?
Can Prettier format HTML and CSS?
Does Prettier work with TypeScript?
Videos
I have Prettier setup as the default formatter already and it's working fine for JSX and JS files.
The weird thing is that it works on save, so when I save it formats HTML correctly, but if I try to do it manually I get: "Extension 'Prettier - Code formatter' is configured as formatter but it cannot format 'HTML'-files".