Astro extension doesn't use `prettier-plugin-tailwindcss` when formatting
Ran into a weird issue when setting up automatic Tailwind class sorting inside a pnpm-based Astro project. I tried to resolve it, but I was unable to find a solution myself; could anyone point me in the right direction, please 🥺
I have
I am using
prettier
and prettier-plugin-tailwindcss
installed as devDependencies:
I am using
prettier-plugin-{astro,tailwindcss}
inside my prettier.config.cjs
, configured as the docs (https://github.com/tailwindlabs/prettier-plugin-tailwindcss#compatibility-with-other-prettier-plugins) say:
And formatting with Prettier CLI works:
However, when I format the code inside VSCode using the Astro extension, it only pretty prints the code, but doesn't sort Tailwind classes. I can't use the Prettier extension as a formatter, because it cannot format 'Astro'-files
. This is a big annoyance, since I'm used to classes auto sorting on save, so it's painful having to run prettier
in a terminal.
Is this a configuration problem, or is it an issue with the Astro extension?GitHub
GitHub - tailwindlabs/prettier-plugin-tailwindcss: A Prettier plugi...
A Prettier plugin for Tailwind CSS that automatically sorts classes based on our recommended class order. - GitHub - tailwindlabs/prettier-plugin-tailwindcss: A Prettier plugin for Tailwind CSS tha...
2 Replies
I had the same problem, but managed to fix it here https://github.com/ronanru/blog/blob/master/prettier.config.cjs
GitHub
blog/prettier.config.cjs at master · ronanru/blog
Contribute to ronanru/blog development by creating an account on GitHub.
Thankss a lot, that solved the problem for me as well! It appears as if the
pluginSearchDirs: ["."]
was the solution. Not sure if it's Astro VSCode's fault for not finding the plugin, should we maybe open an issue to polish this part of the DX?