I created my Svelte project using [email protected]
npx [email protected] create app
Added the TailwindCSS package
npx [email protected] add tailwindcss
And then tried to install shadcn-svelte
npx shadcn-svelte@next init
However couldn't because there was no tailwind.config.js file.
I tried to run the init process for TailwindCSS to get a tailwind.config.js and it didn't work. I tried to create a config file manually and it didn't work either.
However creating a project with [email protected] and adding -initializing flag the TailwindCSS package solved the problem. I am curious why is that?
TailwindCSS v4 was recently released. Since then, running npm install tailwindcss installs v4 instead of v3. To install v3, use this command:
npm install tailwindcss@3
vite.config.js
import { defineConfig } from 'vite'
import { sveltekit } from '@sveltejs/kit/vite'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
plugins: [
tailwindcss(),
sveltekit(),
],
css: {
transformer: 'lightningcss'
}
});
style.css
@import "tailwindcss";
The Shadcn installation guide is incorrect. Using
npm install tailwindcssinstalls TailwindCSS v4 by default, but the guide references the v3 installation. To install v3, you can usenpm install tailwindcss@3until Shadcn officially supports TailwindCSS v4. Aside from this, I believe you should be able to overcome the issue by reviewing the TailwindCSS v4 installation steps.
Some important changes in v4 have not yet been adopted by Shadcn. I wrote more about this here:
The init process has been deprecated. It is no longer usable as it has lost its purpose.
The CSS-first configuration has been introduced with many new and useful CSS directives, eliminating the need for the tailwind.config.js file.
But the legacy JavaScript-based configuration can still be used with the @config directive.
Now, Shadcn officially started supporting TailwindCSS v4. See:
shadcn-ui/ui #6585: Known issues - GitHubIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With