英文:
prettier-tailwind-plugin isn't working as expected when I hit save in VSCode
问题
I installed the prettier-plugin-tailwindcss and it successfully sorts the Tailwind classes when I run Prettier using npx prettier --write index.html
. However, when I hit save in VScode, the prettier-plugin-tailwindcss doesn't sort the Tailwind classes as expected.
I'm following this tutorial and this documentation. As you can see I set the dev dependency correctly and have a .prettierrc.json
in the project.``
I was expecting that when I hit save it will automatically work as expected which is to sort tailwind classes but the plugin only works if run the prettier using npx prettier --write index.html
Things I tried:
I set the format on save to true and set the paths but it didn't resolve the problem.
英文:
I installed the prettier-plugin-tailwindcss and it successfully sorts the Tailwind classes when I run Prettier using npx prettier --write index.html
. However, when I hit save in VScode, the prettier-plugin-tailwindcss doesn't sort the Tailwind classes as expected.
I'm following this tutorial and this documentation. As you can see I set the dev dependency correctly and have a .prettierrc.json
in the project.``
I was expecting that when I hit save it will automatically work as expected which is to sort tailwind classes but the plugin only works if run the prettier using npx prettier --write index.html
Things I tried:
I set the format on save to true and set the paths but it didn't resolve the problem.
答案1
得分: 1
转到“设置 > 文本编辑器 > 格式”并选择“保存时格式化”。
英文:
Go to Settings > Text Editor > Formatting
and select "Format on Save".
答案2
得分: 1
EDIT:
此外,我发现如果有无效的HTML,prettier会报错,不会进行格式化。您可以在终端中检查这些错误 'CTRL + SHIFT + U'。这可能更多是关于'Prettier'而不是TailwindCSS的问题。
我过去几天一直遇到这个问题,经过数小时的浪费时间后,我终于解决了它,但我仍然不知道是什么确切地修复了它,但这是我所做的,希望能帮助其他人。
请注意,一切都对我正常工作,然后无缘无故停止工作,最后我通过变得沮丧并强行解决了这个问题,以下是我采取的最终步骤:
- 我彻底删除了 'the.prettierrc.json' 文件
- 设置 -> 搜索:'prettier' -> 取消选中 'Prettier: Require Config' 复选框。
- 我禁用了几乎所有我没有使用的扩展程序。我试图定位格式化应用程序并进行了大规模清理。
- 我打开了一个要测试的文件 -> CTRL + SHIFT + P -> 'Format Document With'
这导致了一个以前没有的提示,要求我选择默认的格式化程序 -> 选择 'Prettier'。
其中一个事情解决了问题,现在一切恢复正常。
英文:
EDIT:
Also, I found out that if there's invalid html, prettier will spit errors and no formatting will happen. You can check for those errors in the terminal 'CTRL + SHIFT + U'. Probably more of a 'Prettier' thing rather than TailwindCSS thing.
I've had this issue for the past few days and I've managed to solve it after hours of wasted time and I still don't know what precisely fixed it, but here's what I did, hopefully it will help someone else out.
Just note, everything was working normally for me, then it stopped for no apparent reason, in the end I solved it by getting frustrated and I just brute forcing my way out, here's the finals steps I took:
- I deleted 'the.prettierrc.json' file altogether
- Settings -> Search: 'prettier' -> Uncheck the 'Prettier:Require Config' box.
- I disabled pretty much any extension I wasn't using. I was trying to target formatting apps and decided on a big clean up.
- I opened a file to test with -> CTRL + SHIFT + P
-> 'Format Document With'
This resulted in a prompt I hadn't had previously which asked me to choose my default formatter
-> Choose 'Prettier'.
One of those things did it, now I'm back in business.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论