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

  1. Follow Documentation for setting up vite react project.
  2. 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

Most upvoted comments

If someone stumbles upon this issue from Google, add the following tailwind headers to index.css of you project -

@tailwind base;
@tailwind components;
@tailwind utilities;

Just add the following to your index.css:

@tailwind base;
@tailwind components;
@tailwind utilities;

And add the following to your tailwind.confirg.js

 content: ["./src/**/*.{js,jsx,ts,tsx}"],

If someone stumbles upon this issue from Google, add the following tailwind headers to index.css of you project -

@tailwind base;
@tailwind components;
@tailwind utilities;

In 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.css in the src folder where main file is and just add the mentioned code and imprort this file in your main.ts/index.ts

@tailwind base;
@tailwind components;
@tailwind utilities;

just 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.

  1. Update your /src/index.css file: Add the following Tailwind directives:

    @tailwind base;
    @tailwind components;
    @tailwind utilities;
    
  2. Configure your tailwind.config.js file: Ensure that the content property includes all relevant file extensions. It should look like this:

    module.exports = {
      // other configurations
      content: ["./src/**/*.{js,jsx,ts,tsx}"],
      // other configurations
    };
    

The previously stablished solution does not work anymore since tailwind v4 does not support @tailwind rules. Got the following error:

Image

I encountered a similar issue today when using Tailwind v4. My globals.css looks like this:

@import "tailwindcss";

This can not be detected by the latest shadcn cli (v2.3.0) because the code is written like this:

// packages/shadcn/src/utils/get-project-info.ts
for (const file of files) {
  const contents = await fs.readFile(path.resolve(cwd, file), "utf8")
  // Assume that if the file contains `@tailwind base` it's the main css file.
  if (contents.includes("@tailwind base")) {
    return file
  }
}

In a commit 2 days ago https://github.com/shadcn-ui/ui/commit/5ef2bc5f455dfc394116267788c0514b696e13b0, this issue is fixed:

for (const file of files) {
  const contents = await fs.readFile(path.resolve(cwd, file), "utf8")
  if (
    contents.includes(`@import "tailwindcss"`) ||
    contents.includes(`@import 'tailwindcss'`) ||
    contents.includes(`@tailwind base`)
  ) {
    return file
  }
}

So after new release you need at least one css/scss file containing one of these lines

@tailwind base;
// or
@import "tailwindcss";
// or
@import 'tailwindcss';

to allow shadcn to detect your tailwind configuration.

People who are using SCSS for styling in React + Vite + TypeScript, you can just create an index.css in the src folder where main file is and just add the mentioned code and imprort this file in your main.ts/index.ts

@tailwind base;
@tailwind components;
@tailwind utilities;

@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

just 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.

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:

✔ Preflight checks.
✔ Verifying framework. Found Vite.
✖ Validating Tailwind CSS.
✔ Validating import alias.

No Tailwind CSS configuration found at /project-folder-path.
It is likely you do not have Tailwind CSS installed or have an invalid configuration.
Install Tailwind CSS then try again.

I think only the canary build supports tailwind v4 right now https://ui.shadcn.com/docs/tailwind-v4

Yes, this is the only way it works for me: npx shadcn@canary init

omy thank you so much, using npx shadcn@canary init instead of npx shadcn@latest init solved it for me (I didn’t wnt to fall back to tailwind 3)

if anyone is having issues while installing shadcn, kill the react server and run the command

I tried running it but still there seems to be some issue with it validating the tailwind css config file

Image

any idea how to solve it?

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,.

I think only the canary build supports tailwind v4 right now

https://ui.shadcn.com/docs/tailwind-v4

Yes, this is the only way it works for me: npx shadcn@canary init

This solution has 2 steps:

 1. Add these three commands in index.css or global.css 
     @tailwind base;
     @tailwind components;
     @tailwind utilities;
     
  2. Change only content values like the below
  export default {
             content: ['./app/**/*.{js,ts,jsx,tsx}']
   ...}

Why 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.css file from ./public directory to the ./src/styles directory

Same here - first time trying to use ShadUI with React/Remix/Vite/Tailwind for building a Shopify storefront.

Basic init

  shadcn@2.0.6
Ok to proceed? (y) y
✔ Preflight checks.
✔ Verifying framework. Found Remix.
✖ Validating Tailwind CSS.
✖ Validating import alias.
No Tailwind CSS configuration found at C:\GitHub\XXXX\hydrogen\hydrogen.
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/remix to get started.

No import alias found in your tsconfig.json file.
Visit https://ui.shadcn.com/docs/installation/remix to learn how to set an import alias.

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).

@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';

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

export default {
 content: ['./app/**/*.{js,ts,jsx,tsx}']
...}

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;