ui: [bug]: New Shadcn CLI for VITE React Projects - No Tailwind CSS configuration found
Describe the bug
When following the vite project setup guide you will get an error when you get to the step where you run the pnpm dlx shadcn@latest init command. This is due to the index.css missing the tailwind css headers. The documentation needs to be updated at step 2 to.
I’ve created a pull request with the fix here https://github.com/shadcn-ui/ui/pull/4676
Affected component/components
None
How to reproduce
- Follow Documentation for setting up vite react project.
- Get to step 6 and run the command to get the error.
Codesandbox/StackBlitz link
No response
Logs
PS C:\Users\Dwight\Documents\Develop\Typescript\React\pet-form-lhs> npx shadcn@latest init
✔ Preflight checks.
✔ Verifying framework. Found Vite.
✖ Validating Tailwind CSS.
✔ Validating import alias.
No Tailwind CSS configuration found at C:\Users\Dwight\Documents\Develop\Typescript\React\pet-form-lhs.
It is likely you do not have Tailwind CSS installed or have an invalid configuration.
Install Tailwind CSS then try again.
Visit https://tailwindcss.com/docs/guides/vite to get started.
System Info
Windows 11
Before submitting
- I’ve made research efforts and searched the documentation
- I’ve searched for existing issues
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 91
- Comments: 54
Commits related to this issue
- fix(tailwindcss,shadcn-ui): Add the `@tailwind` directives to avoid error to avoid error when running the `shadcn-ui` init command Ref: https://ui.shadcn.com/docs/installation/vite https://t... — committed to rnazmo/my-web-tools by rnazmo 2 years ago
- fix(tailwindcss,shadcn-ui): Add the `@tailwind` directives to avoid error to avoid error when running the `shadcn-ui` init command Ref: https://ui.shadcn.com/docs/installation/vite https://t... — committed to rnazmo/vite-react-ts-tailwind-template by rnazmo 2 years ago
If someone stumbles upon this issue from Google, add the following tailwind headers to
index.cssof you project -Just add the following to your
index.css:And add the following to your
tailwind.confirg.jsIn my case I added ithem in src/styles/globals.css
People who are using SCSS for styling in React + Vite + TypeScript, you can just create an
index.cssin the src folder where main file is and just add the mentioned code and imprort this file in yourmain.ts/index.tsjust add these lines in index.css or in global.css
@tailwind base; @tailwind components; @tailwind utilities;
and than you need to add the following in tailwind.config.css
content: ["./src//*.{js,jsx,ts,tsx}"],**
otherwise tailwind will not properly load.
It works after following https://tailwindcss.com/docs/guides/vite
Update your
/src/index.cssfile: Add the following Tailwind directives:Configure your
tailwind.config.jsfile: Ensure that thecontentproperty includes all relevant file extensions. It should look like this:The previously stablished solution does not work anymore since tailwind v4 does not support
@tailwindrules. Got the following error:I encountered a similar issue today when using Tailwind v4. My
globals.csslooks like this:This can not be detected by the latest
shadcncli (v2.3.0) because the code is written like this:In a commit 2 days ago https://github.com/shadcn-ui/ui/commit/5ef2bc5f455dfc394116267788c0514b696e13b0, this issue is fixed:
So after new release you need at least one
css/scssfile containing one of these linesto allow
shadcnto detect your tailwind configuration.@Amankori2307 Thank you, this worked!
If you’re using v4 make sure you add the import alias in “src/index.css”.
@import "tailwindcss";Better follow the steps from here: Tailwind installation vite
I think only the canary build supports tailwind v4 right now
https://ui.shadcn.com/docs/tailwind-v4
Today with Tailwind 4 only its necesaary
@import "tailwindcss";(pythonenv) ! ◰pythonenv ~/P/p/front zaki *… npx shadcn@latest init ✔ Preflight checks. ✔ Verifying framework. Found Vite. ✖ Validating Tailwind CSS. ✖ Validating import alias.
No Tailwind CSS configuration found at /home/zaki/Projects/project-2cp/front. It is likely you do not have Tailwind CSS installed or have an invalid configuration. Install Tailwind CSS then try again. Visit https://tailwindcss.com/docs/guides/vite to get started.
No import alias found in your tsconfig.json file. Visit https://ui.shadcn.com/docs/installation/vite to learn how to set an import alias.
I still have the same problem I use it react 19 and tailwind v4 btw tailwind and import alias work correctly so what should I do
I have the same issue with React + Vite using SCSS and TypeScript. TailwindCSS is already installed and working. This is the error I am getting:
I got it to validate and install but than tailwind itself still don’t work in the project. Gave up, using just css until they fix this,.
Yes, this is the only way it works for me:
npx shadcn@canary initWhy is this not in the guide!? I saw it in tailwind instructions but thought nah I won’t do anything the guide didn’t say incase it wants to do its own stuff.
Someone should make a PR to update the doc
I had the same issue and I solved it moving my
index.cssfile from./publicdirectory to the./src/stylesdirectorySame here - first time trying to use ShadUI with React/Remix/Vite/Tailwind for building a Shopify storefront.
Basic init
Firstly, I most definitely have Tailwind installed and is working like a dream.
Secondly, the second step in the instructions in the second link above regarding an import alias, is part of the problem. Step 2 in those instructions causes the above error - Chicken / Egg situtation.
I do not use the @tailwind references as above, but instead use the below (which I believe is just as valid and recommended for use with postcss …and works fine).
Happens on either install or if you try and add a component e.g. calendar.
I do have a configuration files for tailwind.config.js and tsconfig.js.
The configuration is valid because it is working. My files are not within src it is within app.
My tailwind config has the following content line
Hope this helps and any suggestions welcome.
Thanks, Dan.
If you are using js rather then ts then you may come through this problem solution:Enter this in src/index.css @tailwind base; @tailwind components; @tailwind utilities;