-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prettier-plugin-tailwindcss doesn't work with vscode #113
Comments
I was JUST about to say this and you beat me to it by 12min LMAO. +1 on this issue. |
Make that a +2 prettier-plugin-tailwindcs: v0.2.1 My
|
@floormodelcitizen This one is right, that one is wrong 😂 |
Couple of things:
So, as far as I can tell, your project seems to be working on my system at least. I'm testing on macOS Monterey but that shouldn't make a difference here. @kuerme Could you provide a reproduction repo I can take a look at? I've got a windows machine as well I can test with. |
Hi @thecrypticace, You can find a demo repo here. |
Also, if there is some code wrapped in an expression block, even after running
|
@ditoglez That looks like a separate bug to me. Would you please open a new issue? |
@thecrypticace please find the issue here: #117 |
@ditoglez I'm looking at your reproduction repo and it is indeed having problems formatting. But it's not using prettier at all in that project: I can get it to format the code if I run |
@thecrypticace sorry for the late reply. I also saw that the code can be formatted through |
I am facing the same problem when I have multiple plugins in my prettier config. Additionally, I am using a plugin for sorting imports in prettier, but it only enables the last plugin to work. |
Might be related: prettier/prettier#12807 |
same here. It doesn't work with my vscode and 'pnpm' but npm works. |
Am facing the same issue with Nextsjs project on windows. |
Same issue with |
Same issue, Adding this This is my project config:
// For ESLint
"eslint.validate": ["svelte", "javascript", "javascriptreact", "html", "json", "jsonc"],
"editor.codeActionsOnSave": {
"source.fixAll": false
},
"eslint.packageManager": "pnpm",
// For Prettier
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"prettier.requireConfig": true,
// Svelte for VS Code
"[svelte]": {
"editor.defaultFormatter": "svelte.svelte-vscode"
}, |
+1. vs code, sveltekit. not working :'-( |
Same for me |
interestingly, I installed on T3 this evening (figured it gotta work there!!) and, surprisingly, it did NOT work. In disbelief because such a popular setup, I uninstalled and then reinstalled the VS code prettier plug in, and then it worked for me. Seems like a long shot, but anybody running into the same might want to at least try. Good luck! |
I solved this problem after creating |
Going back to my SvelteKit config (after setting it work for NextT3), I discovered that having both .prettierrc and prettier.config file caused the plug-in not to load, given if .prettierrc file contents are an empty json object like so:
Pretty surprising. I went back and forth at least 6 times, assuming I forgot to save a file or something, but consistently reproduced on my machine that having both files keeps prettier for tailwinds from working (even though prettier otherwise working). |
What's going on with the prettier plugin @reinink @adamwathan? The solutions mentioned above don't work. |
I was able to get sveltekit with tailwind & their plugins working following this answer using pnpm. Currently, the readme on tailwind-prettier-plugin recommends changing My current {
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"pluginSearchDirs": ["."],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
} |
The plugin works for me in Nextjs 13 but only when I run my format script. It doesn't actually format on save - the format on save functionality actually stops working entirely after declaring this plugin in my config. When I remove it, format on save is working again |
Same issue here with NextJS 13.2.3. Updated with the just released 0.2.4 version of the plugin and still the same. Manually doing a format with |
Hey folks! If you're having issues with the Prettier plugin, be sure to read the "Compatibility with other Prettier plugins" section of the readme: https://github.com/tailwindlabs/prettier-plugin-tailwindcss#compatibility-with-other-prettier-plugins If you're using our Prettier plugin with another Prettier plugin that's incompatible with ours, it won't work out of the box and you'll need to follow the instructions there 👍 |
Hey @reinink, thanks for the reply. I am not using other prettier plugins. It's a barebones Nextjs 13 project with tailwind and prettier installed. Here is the
I've just discovered that when the file extension is In fact, here is a repo that reproduces the issue: |
I have just got this working. My setup uses:
Firstly, a note on debugging. The Output tab in VS code spits out a load of info whenever prettier runs. This useful because it (A) shows when prettier runs, and (B) shows what config is being used. In my case, I was confused why tailwind classes weren't being sorted even though my document seemed to be formatted, turns out it was a different formatter doing the formatting. I did a bit of digging and found these two issues that set me right (1) (2) TLDR; 1 - Rename
It should now work. Check the Output tab to double check that it's picking up the right config. If Prettier still doesn't format the file, you may have to manually add a file association. Open settings in VS code, search for prettier document selectors, and add a new item: You can also see whether Prettier is recognizing your file in the bottom right hand corner of VS code, a double tick next to Prettier means you're all good. Good luck! |
This fixed the issue for me. {
"pluginSearchDirs": ["."],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }],
"plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"]
}
{
"prettier.requireConfig": true,
"prettier.documentSelectors": ["**/*.svelte"],
"[svelte]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
}
} |
@thecrypticace Thanks for clearing up how we should use |
Scratch all that. If you're using Svelte and pNPM, make sure the file is called |
@rory-orennia Thank yo so much, it worked. I was trying to make it work for weeks. It also works with Svelte now. |
I am using I don't use any extra config files for this like .prettierrc (and similar) mentioned here. |
i am working on nextjs typescript tailwindcss project and i want to use preetier plugin tailwindcss to make my code more pretty can anyone help me out to find the solution, i am using npm |
I fixed it by rolling back the vscode prettier plugin version to v9.2.0. Hope this helps. |
If someone ends here, but is using Astro, not Svelte:
module.exports = {
plugins: [require("prettier-plugin-tailwindcss")],
overrides: [{ files: "*.astro", options: { parser: "astro" } }],
// rest of your custom stuff
} |
Like the users of this issue, I have a solution that works for tested & work with : my own module.exports = {
useTabs: false,
tailwindConfig: "./tailwind.config.js", // ⚠️ Set it so you're sure to call up the Tailwind config in the right place.
trailingComma: 'es5',
semi: false,
singleQuote: true,
quoteProps: 'consistent',
bracketSpacing: true,
arrowParens: 'always',
printWidth: 100,
plugins: [
'prettier-plugin-organize-imports',
'prettier-plugin-organize-attributes',
'prettier-plugin-packagejson',
'prettier-plugin-tailwindcss', // ⚠️ Order is very important place Tailwind prettier plugin at the end
],
overrides: [ // ⚠️ If you are using edge you need also set this to add support for edge
{
files: '*.edge',
options: {
parser: 'html',
},
},
],
}; Don't forget to download VSCode Prettier Extension and add this settings inside your VSCode {
...
"editor.formatOnSave": true,
"[edge]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"prettier.useEditorConfig": false,
"prettier.documentSelectors": ["**/*.edge"],
} here you'll find a Medium that explains how to add support for an extension that doesn't exist in Prettier. (Astra, Edge, Handlebars ...) |
THANK YOU! This worked. Adding the |
@pratyushtewari can you provide a reproduction for this? |
Not sure if my setup is different or this it out of date but I also had to install and update prettier-plugin-astro (the astro vscode extension ships with and uses prettier by default making the config finicky, it only supports prettier v3 around version 11 of the astro plugin). I had another package which install an older version of the astro plugin by default and so I had to run: npm install -D prettier-plugin-astro prettier-plugin-tailwindcss to get the updated, v3 compatible, plugins and then updated my .prettierrc with the list to be: {
"tabWidth": 2,
"useTabs": false,
"bracketSameLine": true,
"plugins": [
"prettier-plugin-astro",
"prettier-plugin-tailwindcss"
]
} |
Hi @thecrypticace - my project is here: https://github.com/pratyushtewari/bbos-components , the prettier.config.js did not work for me but adding .prettierrc worked with the same content inside the config. I think prettier is only looking for the .prettierrc file. |
@pratyushtewari Your project is The following for export default {
"plugins": ["prettier-plugin-tailwindcss"],
} |
@thecrypticace - Thanks! this worked. I am not fluent in ESM much. to me Thanks! |
This still isn't working for me. |
Yeah i have given up and use Headwind (VSCode extension) instead for class sorting |
this works |
For folks using After adding Then I change the config file name to So my final config file is like: module.exports = {
plugins: [
"prettier-plugin-packagejson",
"@trivago/prettier-plugin-sort-imports",
"prettier-plugin-prisma",
"prettier-plugin-tailwindcss",
],
pluginSearchDirs: false,
importOrder: [
"server-only",
"^@([^/]+)(.*)/?(.*)$",
"^@/(.*)/?(.*)$",
"^[./]",
],
// importOrderSeparation: true,
importOrderSortSpecifiers: true,
importOrderGroupNamespaceSpecifiers: true,
}; |
To others facing issues, restarting VS Code can help. Especially if you've changed a config and seen no impact. |
adding this to .vscode/settings.json finally helped me <3 |
Using module.exports = {
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"plugins": [require.resolve("prettier-plugin-svelte"), require.resolve("prettier-plugin-tailwindcss")],
"overrides": [
{
"files": "*.svelte",
"options": {
"parser": "svelte"
}
}
],
"tabWidth": 2
} |
prettier-plugin-tailwindcs: v0.2.1
Tailwind CSS: v3.2.4
Node.js: v18.12.1
Package Manager: pnpm v7.21.0
Operating System: Windows 11
Describe your issue
prettier-plugin-tailwindcss doesn't work with vscode and it's plugin
Svelte for VS Code
andPrettier - Code formatter
;it won't format the *.svelte files (but it formats the html files);
And with the svelte files, the "prettier" has taken effect, cause the
prettier-plugin-organize-imports
andprettier-plugin-css-order
works fine,exceptprettier-plugin-tailwindcss
...,so i think Is there anything that prevents tailwind formatting?...here is my
.prettierrc
The text was updated successfully, but these errors were encountered: