prettier icon indicating copy to clipboard operation
prettier copied to clipboard

Extension 'Prettier - Code formatter' is configured as formatter but it cannot format 'Svelte'-files

Open qupig opened this issue 1 year ago • 7 comments

I know that this issue is related to prettier-plugin-svelte, Svelte for VS Code, prettier-vscode. But the issue is posted in this repo because this is where the damage is directly caused.

After my repeated testing, this issue occurred when prettier was updated to 3.1.1, and also exists in 3.2.0 or the latest 3.2.5 version. In other words, the last working version was prettier v3.1.0

Specific issue manifestations: Upgrading to prettier 3.1.1 or newer versions with only the prettier-vscode plug-in installed will cause the Format Document menu to disappear in svelte files.

If the Svelte for VS Code plug-in is installed at the same time, the error message in the title will be prompted after clicking the Format Document menu.

It looks like the issue is that after prettier was updated to 3.1.1, the svelte support provided by prettier-plugin-svelte was not fed back to the prettier-vscode plugin while the config file remained unchanged.

vscode settings

{
	"[svelte]": {
		"editor.defaultFormatter": "esbenp.prettier-vscode"
	}
}

.prettierrc.json

{
	"plugins": ["prettier-plugin-svelte"],
}

It will work fine via the prettier command line or specifying the vscode formatter as Svelte for VS Code, but it has nothing to do with this issue.

qupig avatar Feb 19 '24 10:02 qupig

We are having the same problem. Reverting back to prettier 3.1.0 did fix the problem, thanks for the info @qupig .

nitriques avatar Feb 20 '24 22:02 nitriques

We are having the same problem. Reverting back to prettier 3.1.0 did fix the problem, thanks for the info @qupig .

It is strange that there is a difference in behavior between 3.1 and 3.2, we need to look into it!

sosukesuzuki avatar Mar 09 '24 12:03 sosukesuzuki

I can add more context, hoping it can help.

  1. We had issues on two macs, all with the latest vs-code and extensions.
  2. Same issues with a windows 11 box.
  3. It only for svelte files, prettier was able to format ts.
  4. I diffed 3.1 vs 3.2 and could not find anything obvious.

nitriques avatar Mar 09 '24 19:03 nitriques

This is indeed strange. I have a project that uses ^3.0.2 and it's perfectly working. Now, I started a new project and it has ^3.2.5 and it can't format .php or .svelte files even when I'm using the same .prettierrc.js. It's as if it's not reading the config files nor running the plugins.

sveltecult avatar Mar 12 '24 22:03 sveltecult

https://github.com/prettier/prettier-vscode/pull/3335 will solve this.

sosukesuzuki avatar Mar 13 '24 05:03 sosukesuzuki

That's good news ! Thanks !

nitriques avatar Mar 14 '24 23:03 nitriques

Still an issue despite https://github.com/prettier/prettier-vscode/pull/3335 being merged.

Synweigh avatar Apr 10 '24 20:04 Synweigh

Having done some testing in the latest environment, it seems that v3.3.3 can no longer reproduce the issue, nor even v3.1.1 where the issue originally occurred.

Seems to have been fixed by prettier-vscode (I'm guessing)?

If everyone can also confirm that this issue has been resolved, I will close the issue?

qupig avatar Sep 16 '24 23:09 qupig

im having this issue with latest vsc + "prettier": "3.3.3"

aplotor avatar Sep 20 '24 02:09 aplotor

@aplotor Same version, but I don't seem to be reproducing the issue anymore.

Just in case, check if you have the latest prettier-vscode extension?

qupig avatar Sep 20 '24 04:09 qupig

@qupig thanks, actually its working. i had to npm install prettier-plugin-svelte. i originally only wanted to use prettier-plugin-tailwindcss but it doesnt work w/o the prior i guess

aplotor avatar Sep 20 '24 22:09 aplotor

@aplotor Of course, prettier cannot parse your svelte file without it.

It looks like this issue no longer exists and I'll close it.

qupig avatar Sep 21 '24 04:09 qupig