visual-studio-codeprettierprettier-vscodevs-code-settings

VScode Prettier Extension Not Formatting on Save


When saving a file that has Prettier configured as the default formatter, nothing happens and the file is not formatted.

I have looked at all the similar questions related to this issue, but they all boil down to setting Prettier as the default formatter in VScode. First of all this will not work for my situation since I only want to use it for HTML, and secondly I have configured Prettier correctly as the default formatter for the file I want to format. I know this because Format Document With... yields: prettier showing as default formatter on html file

If I run that command, Prettier formats the file exactly as I would expect. If I change my settings to use the built-in formatter and save the file, the formatter kicks in and formats the file, just as I would expect. So the real issue is that even though Prettier is formatted as the default, it will not format on save.


Solution

  • After digging a ton, the issue was caused by the workspace setting "editor.formatOnSaveMode": "modificationsIfAvailable". Removing this allowed me to configure the formatter for HTML as Prettier in the workspace without needing to set any User settings.

    Not sure why format on save still worked with the same configuration but a different formatter, but at least it works now.