prettier-plugin-tailwindcss: Incompatibility with other Prettier plugins
To make this plugin work we had to use private Prettier APIs that can only be used by a single plugin at once. This means this plugin is incompatible with other Prettier plugins that are using the same APIs.
This GitHub issue will serve as a place to keep track of which Prettier plugins are incompatible — and hopefully we’ll eventually find some workarounds, or even a proper long term solution. 👍
Known incompatibilities
@trivago/prettier-plugin-sort-imports
prettier-plugin-organize-imports
prettier-plugin-svelte
(see below)prettier-plugin-twig-melody
prettier-plugin-svelte
We’ve bundled the prettier-plugin-svelte
directly into prettier-plugin-tailwindcss
, so if you’d like to use this plugin with Svelte, just uninstall prettier-plugin-svelte
and everything should work as expected.
Workarounds
While I have not tested it yet, @Mattinton provided one possible workaround in this comment.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 52
- Comments: 73 (10 by maintainers)
Commits related to this issue
- chore(deps): remove prettier-plugin-svelte Reference https://github.com/tailwindlabs/prettier-plugin-tailwindcss/issues/31 — committed to hyunbinseo/sbm-work-report by hyunbinseo 2 years ago
- Add fix to make 2 prettier plugins work together ref: https://github.com/tailwindlabs/prettier-plugin-tailwindcss/issues/31#issuecomment-1024722576 — committed to cennznet/app-gov by deleted user 2 years ago
- Spike: Update proposal submit flow (#17) * Rename path from `proposals` to `proposal` * Add fix to make 2 prettier plugins work together ref: https://github.com/tailwindlabs/prettier-plugin-tai... — committed to cennznet/app-gov by ken-futureverse 2 years ago
- add prettier, eslint, typescript and husky diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..dadb977 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "root": t... — committed to nirtamir2/solid-start-starter by nirtamir2 2 years ago
- remove tailwind-sorter added prettier tailwind to project instead. see https://github.com/tailwindlabs/prettier-plugin-tailwindcss/issues/31#:~:text=As%20mentioned%20in,the%20plugins%20array%3A — committed to alivault/nvim-config by alivault 4 months ago
Hey folks! 👋
So just an update on the Prettier plugin compatibility situation. We’ve just released a new beta version of
prettier-plugin-tailwindcss
which improves (or at least we hope it does 😅) compatibility with specific other Prettier plugins, including:prettier-plugin-svelte
prettier-plugin-astro
@trivago/prettier-plugin-sort-imports
prettier-plugin-organize-imports
We’ve taken a new approach with our Prettier plugin where we no longer bundle any third-party Prettier plugins (including the Svelte plugin — more on that below). And, through a safe list, we’ve explicitly added support for the above plugins which currently have known incompatibilities.
We’ve done this by automatically detecting if one of these plugins is installed and enabled in your project, and if it is, we do some magic behind the scenes in our plugin to make sure these plugins still work.
The one gotcha with this approach is that Prettier plugin autoloading is unreliable, because our plugin must come last in the list of plugins. For this reason, you’ll need to explicitly disable the
pluginSearchDirs
option, and define each of your Prettier plugins in theplugins
array:For Svelte users, we no longer bundle the
prettier-plugin-svelte
plugin within our plugin, so you’ll need install and enable it using the instructions above.For Astro users, this new release supports
prettier-plugin-astro
, which you can install in the same way.We’ve released this updated plugin as a beta version since we’re not 100% sure on this approach quite yet, and would really appreciate your help testing it out. You can install it using the
beta
tag:Let me know how it goes! 💪
Would it be possible to add astro support?
I found a new workaround to make
@trivago/prettier-plugin-sort-imports
andprettier-plugin-tailwindcss
work at the same time in React+TypeScript(work in vscode🎉).prettier.config.js
, create a file and move your config to `prettier.config.jsprettier.config.js
.Sample Code
References.
Underlying problem
Underlying problem
After some investigation, I suspect that there is a problem with prettier core
getParsers()
.https://github.com/prettier/prettier/blob/cd9955f1431ca3814ea9b713aa7275ceefa980d9/src/main/parser.js#L15-L25
For example
APlugin does not work when formatted with a ts file, and only BPlugin works.
I assume this is because the
parsers
ingetParsers()
are overwritten for each plugin. I am currently investigating.Hello everyone, another update, we’ve just released v0.2.0, which includes all these plugin compatibility fixes.
You can install it using npm:
We’ve also updated the readme to list all the Prettier plugins that we’ve added explicit support for:
https://github.com/tailwindlabs/prettier-plugin-tailwindcss#compatibility-with-other-prettier-plugins
With all this complete, I am going to close this issue as resolved. Thanks to everyone here for sharing information about incompatible plugins with us! 🙏
Seems this one might be incompatible as well https://github.com/withastro/prettier-plugin-astro
I originally opened issue #26 about
prettier-plugin-organize-imports
- in that specific case, I’m able to work around the incompatibility for now by monkey-patchingprettier-plugin-tailwindcss
so that each overlapping parser uses thepreprocess
function fromprettier-plugin-organize-imports
, like so:This works for now because, from what I can tell,
prettier-plugin-tailwindcss
doesn’t set a preprocessor, andprettier-plugin-organize-imports
does all of its work in the preprocessor.Looking forward to whatever eventual fix removes the need for the patch!
Subscribing to this. Working with Craft CMS, it’s disappointing to see this is incompatible with prettier-plugin-twig-melody.
Hello, Erika from the Astro team here. Any idea when the current
main
will be released?We contributed Astro support 2 months ago now and our users understandably keep asking us to support this. I know there was some needed changes after our PR, but it seems like those changes were merged in a month ago.
If there’s anything we can do to help get this released - please let us know and we’ll gladly contribute!
I think the premise of your question is a bit misplaced. My experience with open-source software, unless funded by big sponsors, is that contributors submit patches mostly to solve their own problems. So either you have to get your hands dirty and submit a PR to solve this, or cross your fingers and hope that someone else has enough motivation to sacrifice their free time one day and do the work for you.
Sup everyone! 👋
Just another update on the Tailwind CSS Prettier plugin. We’ve now added support for a bunch of other Prettier plugins and have released a new beta version for your testing pleasure.
Here’s a complete list of all the plugins we added support for in this release:
@prettier/plugin-php
@prettier/plugin-pug
prettier-plugin-css-order
prettier-plugin-import-sort
prettier-plugin-jsdoc
prettier-plugin-organize-attributes
prettier-plugin-style-order
prettier-plugin-twig-melody
Installing the beta
As previously mentioned, we need to do some shenanigans to get these plugins all working (I’m looking at you
@prettier/plugin-php
), so we’d really appreciate your help kicking the tires on this new version for us.To install this latest beta, add it using npm:
As mentioned in my previous comment, the one gotcha with this approach is that Prettier plugin autoloading is unreliable, because our plugin must come last in the list of plugins. For this reason, you’ll need to explicitly disable the
pluginSearchDirs
option, and define each of your Prettier plugins in theplugins
array:Other plugins
I think this covers all the Prettier plugins mentioned in this issue other than
@shufo/prettier-plugin-blade
, which unfortunately is more complicated since that plugin forks out to a different process and doesn’t provide an AST — just a string. So we’d have to parse the whole Blade file ourselves to be able to sort classes within it, which is a much bigger undertaking.Thank you @reinink 👏
For anyone struggling, this works with
pnpm
:Reading the discussion here, according to Prettier’s team, re-ordering classes should not be done through Prettier but through ESLint, which is why they do not plan to solve it 😅 Should the effort be redirected to an ESLint plugin? (official support for the existing ones?)
how about this issue
For those that are using
eslint
(with autofix) in conjunction withprettier
, eslint-plugin-tailwindcss might be a viable alternative.Thanks for updating this. Sad it’s still incompatible with Twig 😦
@Princesseuh I think it’s still blocked by what @thecrypticace outlined here: https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/87#issuecomment-1218432784
We’re really busy trying to get Tailwind CSS v3.2 out the door this week and then out for a team retreat the following week, but we can look at this again the first week of November. One idea we might need to explore is multiple plugins, like a
prettier-plugin-tailwindcss-astro
plugin and a separatepretter-plugin-tailwindcss-svelte
plugin or similar since it seems to be proving challenging to build something that works everywhere 😕Might be a bit of an edge case. But I am using Laravel and subsequently Blade template files.
So that prettier runs on these files I am using @shufo/prettier-plugin-blade. But as this issue suggests, Tailwind classes are not sorted when run with this plugin.
Hey @blooddrunk, this workaround worked for me:
Related to this answer.
Are all these incompatibilities meant to be fixed at some point, or is this issues point to inform us that we can’t use a combination of said plugins without odd workarounds?
Looking forward for this to be compatible with @ianvs/prettier-plugin-sort-imports
Agreed, having this issue as well.
I see what you did there.
Beautiful thanks! This worked for me (Next 13, pnpm)
@TrevorLeeman are you using pnpm? I think I noticed the same thing when I moved to pnpm from yarn (v1). I’ll try and get back to this thread with a result.
EDIT: confirmed. Reverting to Yarn solved the issue 😃
@kagurazaka-0 Thanks for sharing. This looks like a promising solution, but I was personally not able to get it working. Continuously got this error in the Prettier output after making the change to the
prettier.config.js
:When only using
plugins: [require('prettier-plugin-tailwindcss')]
orplugins: [require('@trivago/prettier-plugin-sort-imports')],
individually, Prettier works as expected.It seems to be incompatible with https://github.com/trivago/prettier-plugin-sort-imports
@blooddrunk @bryanbarrios Just a heads up that we’ve also added support for
@ianvs/prettier-plugin-sort-imports
: https://github.com/tailwindlabs/prettier-plugin-tailwindcss/releases/tag/v0.2.3@mreduar Hey, yes, you still to disable the
pluginSearchDirs
and list all your plugins in theplugins
array, putting Tailwind CSS last (as per the readme).If it’s not working there is probably something else wrong. Feel free to create a minimal reproduction and we can have a closer look 👍
Hiya, did anyone found a workaround when using pnpm ?
I figured out what I was doing wrong and the reason I couldn’t get it to work for SvelteKit before was because I was trying to include the plugin inside
.prettierrc
which for some reason breaks it, so don’t include it and it should pick it up.👎️ .prettierrc
Here are the steps for SvelteKit users:
pnpm i -D prettier-plugin-tailwindcss
pnpm remove prettier-plugin-svelte
You can keep using the
svelte.svelte-vscode
formatter.You can look at the updated repo if you need an example.
I for one can say that I can install and integrate:
@tailwindcss/forms
and it has 0 affect on this Prettier plugin.I don’t particular care for the defaults put forth in the forms extension, so I don’t usually use it. Just tried it out when I saw these issues.
As to all of the other plugins, I don’t personally use all of those, but other ones such as standard prettier, or prettier for Jest I do use and never had any issue.
Also incompatible with
prettier-plugin-organize-attributes
If you want a workaround, you could use the prettier
--config
flag and have two different configs (using the sharing configurations patter for consistent formatting).This solution won’t work with your IDE on saving, but it could work with a lint-stage solution.
It’s not a pretty solution, but I think it’s possible for those that strongly want multiple plugin support.
I, personally, have decided to use the tailwind prettier plugin on its own for now to avoid adding this much complexity to my projects.
what’s progress of this issue, i run into this issue, it will break plugin
prettier-plugin-organize-imports
,@rwwagner90 It’s not that this plugin is incompatible with
prettier-plugin-astro
, but this plugin only works with a few extensions (such asvue
,html
, etc).The issue was a problem with my VSCode, all worked after restart
Seems like it’s not working when used with “prettier-plugin-organize-attributes”
It is still not working for me:
.prettierrc.cjs
package.json
Based on : https://github.com/tailwindlabs/prettier-plugin-tailwindcss#compatibility-with-other-prettier-plugins
🤔
@ramblehead Hey! So we actually already have support for
prettier-plugin-jsdoc
, see here: https://github.com/tailwindlabs/prettier-plugin-tailwindcss#compatibility-with-other-prettier-plugins@sameeranand1 Done: #102 🤙
This has been released as
0.2.0-beta.3
.@reinink Can you add support for
@shopify/prettier-plugin-liquid
? This is for Shopify themes. https://github.com/tailwindlabs/prettier-plugin-tailwindcss/issues/98@mattcroat I really appreciate this, and I did try but IDE kept showing
Saving '+page.svelte': Running 'Svelte for VS Code' Formatter
toast message while I was trying to save. If I try to navigate to a different file the toast message disappears and saves the file.The formatting was successful by the end of the wait and consequent save did not have this problem. Just throwing this here to see if others faced this issue. I faced this issue both with my personal repo and also the repo shared by @mattcroat
cc. @reinink
Would be very nice, if we had support for this one: https://github.com/prettier/plugin-pug The markup used in
pug
can look like this:h1(class="text-center font-serif")
, which is in terms of classes is the same asHTML
. If anyone has a possible solution, I’d be very grateful. Thanks!I found a workaround on this one
Create a
tailwind.shared.config.js
contains all the things without@tailwindcss/forms
Then in normal
tailwind.config.js
add the plugins back.in
.prettierrc.js
use the config file without@tailwindcss/forms
https://github.com/tailwindlabs/prettier-plugin-tailwindcss/issues/31#issuecomment-1195411734 @kagurazaka-0 Thank you! I try it and it works well! Now I wait until I would be able to remove this workaround.
@manavm1990 This issue is specifically in regards to those other plugins, not for the standard prettier plugin which this tailwind plugin was built for and can be used in tandem with forms 👍
Any workarounds @guilhermetod ?
Thanks for the idea, I made a lintstaged script to run eslint (with prettier tailwindcss) + prettier (with prettier sort imports), here is an example
@nunocasteleira this issue is related to prettier plugins conflicting with each other.
If your system can’t find
@tailwindcss/forms
try reinstalling it withnpm install @tailwindcss/forms
.If you continue to have problems open an issue on the forms repo.