prettier-vscode icon indicating copy to clipboard operation
prettier-vscode copied to clipboard

.vue files cannot be formatted

Open DimplesY opened this issue 2 years ago • 8 comments

Summary

Version 9.9.0, vue files cannot be formatted when a configuration file exists in the project directory

  1. Prettier - Code formatter 9.9.0
  2. Vue Language Features (Volar) 0.40.13

Actual result

image image

DimplesY avatar Sep 27 '22 15:09 DimplesY

I have the same problem and it doesn't work on .scss file too

BabyLy233 avatar Sep 29 '22 03:09 BabyLy233

I experienced the same problem also with .html files.

It happens with version v9.9.0. I installed the previous version (v9.8.0) and the issue disappeared.

andr35 avatar Oct 01 '22 09:10 andr35

Same issue.

holazz avatar Oct 03 '22 10:10 holazz

This bug is missing information needed to diagnose the problem. Please see our guide on how to open a good issue and provide the missing information. Most configuration-related issues can only be resolved by providing a full repro. If you don't provide a sample to reproduce your issue, your bug will most likely be closed.

github-actions[bot] avatar Oct 03 '22 21:10 github-actions[bot]

Volar will find all corresponding formatting tools according to configurations.

By default, these formaters are:

More information, here.

Seems like, we can not change the behaviour of Volar by setting "editor.defaultFormatter": "esbenp.prettier-vscode" in settings.json. Currently, I do not know why, too.

Back to this issue, if you want to use prettier to format .vue files, here is a workaround.

Make sure:

  • installed prettier and eslint, npm packages as project dependencies and VSCode plugins
  • .eslintrc.cjs in your project root, and make sure '@vue/eslint-config-prettier' is on the last line of prop extends
  • some additional configurations in settings.json, like this:
"editor.codeActionsOnSave": {
    "source.fixAll": false,
    "source.fixAll.eslint": true,
    "source.organizeImports": false
}

~~Then, ESLint will format your .vue files automatically by calling prettier, every time you save files.~~

Edit: sorry, seems like the paragraph above I wrote makes nonsense totally.

To mount Volar extension, and format .vue files with a set of rules as well,

That is my poor insights. Hope this helps.

ghsgz avatar Mar 25 '23 12:03 ghsgz

Facing this after a recent VS Code update. Had to downgrade the extension to version 8.2.0 (9.8.0 wasn't enough for me) until it started to work. I'm on Windows 11 and WSL2 Ubuntu 22.04. Willing to help with debugging.

Igonato avatar Jun 15 '23 16:06 Igonato

I faced same problem, But when I reboot my pc. All problem was fixed.

quroom avatar Apr 11 '24 05:04 quroom

Same error for me, if downgrade to Prettier version 9.14.0 works fine.

esorribas avatar Jun 10 '24 20:06 esorribas