prettier-plugin-tailwindcss: vscode prettier formatter doesn't match `npx prettier`
What version of prettier-plugin-tailwindcss are you using?
v0.5.14
What version of Tailwind CSS are you using?
v3.3.0
What version of Node.js are you using?
v20.12
What package manager are you using?
yarn
What operating system are you using?
Mac OS
Describe your issue
I use the classes below:
className="data-[side=top]:animate-test flex"
and in my tailwind.config.ts
const config = {
theme: {
extend: {
animation: {
test: 'FadeIn 400ms cubic-bezier(0.16, 1, 0.3, 1)',
}
}
}
}
and my .prettierrc.js:
module.exports = {
plugins: ['prettier-plugin-tailwindcss'],
tailwindFunctions: ['cn'],
tailwindConfig: './tailwind.config.ts',
semi: true,
trailingComma: 'all',
singleQuote: true,
printWidth: 120,
tabWidth: 2,
};
When i run npx prettier --write it sorts the classes in a different order then when i use the prettier formatter in vscode (option + shift + f)
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 6
- Comments: 17 (2 by maintainers)
The problem is that the Tailwind CSS config is not found correctly. To fix it use an absolute path:
Example of Prettier config that works
Happens to me on both, macOS & windows
@thecrypticace Here is a minimal reproduction + screen recording using Tailwind v4 alpha:
https://github.com/aaronadamsCA/prettier-plugin-tailwindcss-issue-270
My best guess at what’s happening:
my-app/src/tailwind.css, so it uses the Tailwind v4 sort order.One workaround is
cp .prettierrc.json my-app/, but obviously we’d rather not copy/link our Prettier config into every package.I realize this is v4 and most other reports are v3, but I have a feeling the root cause is ultimately the same—incompatible config file resolution.
I can reproduce this issue on Tailwind 3.4.3