Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

funkyjamma's avatar

Cannot get laravel to work with tailwindcss 4

I have been trying for hours now to get the new tailwind to work with laravel and nothing seems to work. I even tried setting up a new project following the instruction on the tailwind website and nothing seems to work. Is anyone else having these issues?

I can get other versions to work but just not 4.

0 likes
39 replies
funkyjamma's avatar

@jlrdw sure did I can record a video and upload it to youtube in a bit also I followed the directions exactly.

funkyjamma's avatar

Here is my vite config https://snipboard.io/5Zo6Nk.jpg

Here is my app.css https://snipboard.io/EvBWmc.jpg

here is my view https://snipboard.io/VFb49k.jpg

to install tailwind in the project directory i ran. npm install tailwindcss @tailwindcss/vite

then updated my files then

npm run dev

Ive even tried npm install just in case there were any missing files. and there were but also that didnt fix the issue.

and here is the error when i try to build https://snipboard.io/5HXTlB.jpg

Here is a short video showing what I am doing

https://www.youtube.com/watch?v=RszHhXJKmcA

RemiM's avatar

Steps to Set Up Tailwind CSS 4:

Before proceeding, remove any existing Tailwind CSS and PostCSS npm packages to avoid conflicts:

npm uninstall tailwindcss postcss
  1. Install Tailwind CSS and the PostCSS plugin:
npm i -D tailwindcss @tailwindcss/postcss
  1. Add the Tailwind PostCSS plugin to your postcss.config.js file:
plugins: {
    "@tailwindcss/postcss": {}
}
  1. Import Tailwind CSS in your app.css file:
    @import "tailwindcss";
  1. Don’t forget to include your CSS file in your Laravel Blade template using:
@vite(['resources/css/app.css'])
  1. Restart your dev server:
npm run dev

Bonus Tip (for VSCode users):

If auto-completion for Tailwind CSS doesn’t work in your Laravel Blade files, add the following to your settings.json file:

    "files.associations": {
        "*.css": "tailwindcss"
    },
   "editor.quickSuggestions": {
        "strings": "on"
    },

With these steps, your Tailwind CSS setup and development experience should work smoothly!

5 likes
funkyjamma's avatar

@RemiM unfortunately this also didn't work its still the same. The errors didn't even change.

RemiM's avatar

@funkyjamma Just to be sure, did you remove the old tailwind devDependencies from your package.json before installing the new packages?

Anyway, you shouldn’t need anything else to get it running.

Also, make sure you're not importing Tailwind in your vite.config.js file. It should look like this (as generated by a fresh Laravel install):

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true,
        }),
    ],
});

The full postcss.config.js file:

export default {
    plugins: {
        "@tailwindcss/postcss": {},
        autoprefixer: {},
    },
};

The full barebone app.css:

@import "tailwindcss";
2 likes
funkyjamma's avatar

@RemiM yeah i even started a whole new project to test your instructions it didnt work. My files look like you state.

I just removed it from vite and now i get this error.

in order to even view these error i need to run npm run build, npm run dev shows no error but also just doesnt work.

https://snipboard.io/mu67W1.jpg

I just noticed the package.json part i think this is where my issue may be. Do i just delete the tailwind thats there or do i need to change the version number?

I figured it out It got rid of the errors but now its just not working without errors.

Sinnbeck's avatar

Can you perhaps put the test app on github so we can test it ?

RemiM's avatar

@funkyjamma Remove the old entries in the package.json. The tailwind and the postcss lines entirely. Then process to install the new package.

funkyjamma's avatar

@RemiM this works only when i run dev build when i do dev run it doesnt work.

RemiM's avatar

Just to confirm, you keep npm run dev running in the background while developing, right?

Also, it might be helpful to clarify: npm run dev is used for development purposes, providing a live-reloading server, whereas npm run build generates an optimized production-ready build of your application.

mark-p's avatar

I had the exact same problem as @funkyjamma on a new Laravel project created with Herd but I followed @RemiM instructions and it now works.

brocorp's avatar

@funkyjamma just run npm install @tailwindcss/postcss and then relaunch npm run dev

This package is problably missing in your package.json.

adrianojsle's avatar

The bug happens because the recent version of Laravel already comes with a pre-installed version of Tailwind. Do the following:

1- Remove all Tailwind and PostCSS dependencies from the package.json file 2- Run "npm i -c" 3- Follow all the steps from tutorial Tailwind Vite Laravel official doc 4- Run "npm i @tailwindcss/postcss" 5- Change the postcss.config.js to: export default { plugins: { "@tailwindcss/postcss": {}, autoprefixer: {}, }, }; 6- Run "npm run dev -c"

11 likes
Keviin's avatar

@adrianojsle Thank you very much it works for me, I must say that I really struggled while the solution was so simple. I would like to know if you can help me to solve the problems of importing external plugins with version 4 of tailwindcss since in previous versions it was done in the tailwind.config.js file in the plugin part and in v4 when I try to import the plugins from postcss.config.js it gives me errors. And the plugin concerns the Preline package which is also a library of pretty great components based on tailwind

MarkJC's avatar

@adrianojsle Hi @adrianojsle. Thank you. Your advice worked for me. I have a Laravel 12 Livewire starter kit installation and your advice was the only thing on the Internet that helped me.

Curtmantle's avatar

I created a fresh install and was getting the same message when trying to use Tailwind so I followed @RemiM's instructions. The following is a summary of the process I followed:

  1. Remove the tailwindcss and postcss dependencies from package.json.
  2. Install tailwindcss and tailwindcss/postcss via the terminal
npm i -D tailwindcss @tailwindcss/postcss
  1. Replace the existing tailwindcss plugin in postcss.config.js with 'tailwindcss/postcss
export default {
    plugins: {
        "@tailwindcss/postcss": {},
        autoprefixer: {},
    },
};
  1. Remove the auto generated tailwind declarations from app.css and replace them with the new import.
@import "tailwindcss";
  1. Ensure you have the reference to the app.css file in your root Blade template. To test you can replace the markup in welcome.blade.php with the following:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>        <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Laravel</title>

    <!-- Fonts -->
    <link rel="preconnect" href="https://fonts.bunny.net">
    <link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
    @vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
<body class="font-sans antialiased dark:bg-black dark:text-white/50">
<h1 class="text-center text-3xl text-yellow-600">Test Tailwind</h1>
</body>
</html>

I've tested this twice with a new Laravel project and it works. Thanks to @remiM.

4 likes
puklipo's avatar

Let's wait for Laravel's official support for Tailwind 4.

Tailwind's documentation is not useful.

ziddkh's avatar

I had the same case, to solved this please remove postcss.config.js file and these two packages from your package.json

"postcss": "^8.4.47",
"tailwindcss": "^3.4.13",

Then run npm install && npm install tailwindcss @tailwindcss/vite after that please follow the installation instruction from tailwindcss, and run npm run dev again.

It should be works correctly

mani273's avatar

@funkyjamma I simply upgraded from tailwind v3 to tailwind v4 in my laravel version 11 + inertia js 2.0 + react + typescript project by following the official upgrade guide from tailwind.

Before attempting this create a new branch of your project since the following commands will also modify your source files.

Simply run the following command:

npx @tailwindcss/upgrade

OR if you are using sail, prefix sail infront of the command:

sail npx @tailwindcss/upgrade

NOTE: remember to re run the npm server or rebuild assets after this with either of the below commands.

npm run dev

or

npm run build

OR if you are using sail

sail npm run dev

or

sail npm run build

This will upgrade everything including your npm dependencies, your previous config files and also your source files since several breaking changes were introduced.

You might want to watch for some edge cases before committing the changes though!

However fear not the above command worked as is and I had to do almost 0 changes. It even properly copied all my shadcn theme variables to resources/app.css and cleared some of the edge cases too!

The only thing I had to look out for was some hotfix I used for incorrect popover width for some shadcn components which was nothing major (just a minor visual bug) and it affected only 2 files. The fix was already available on github discussions and that solved it!! Just remember that if you were using some bruteforce or hacky tailwind solutions, you might want to look out for those!

bionary's avatar

I tried everything here. Wasted 5-6 hours on this and still could not get tailwind 4 to work. I have a Laravel install that was originally Laravel version 9 but was upgraded to v.11 about six months ago. I'm also running Filament 3 which complicates things maybe.

I really wish front end developers who produce open source packages would limit their caffeine intake and get some deep hobbies. The speed at which they feel the need to "innovate", push code and otherwise waste thousands of collective man-hours by constantly changing protocols and inventing new ways to complicate front end tech is mind boggling.

The new goal for front end package devs should be to see how few git pushes they can make.

HyperCanis's avatar

Hi,

I don't know if I missed something here but as I see it author is trying to make it work with VITE and all the tutorials are for POSTCSS.

Never the less it did help me find a solution!

I have fresh Laravel 12 project and I followed all the instructions for TAILWIND/VITE and it didn't work.

In this post I found command: npm uninstall tailwindcss postcss

And after I ran it, it started working!

Lazyy's avatar

Hey Bro I got a fix for You Whenever u start a new Laravel 12 Project just run this command in the project directory .

npm install --save-dev vite laravel-vite-plugin

then when you want to run your application just run "npm run dev" and "php artisan serve"

and include this in every blade.php file in the head section

@vite(['resources/css/app.css', 'resources/js/app.js'])

This is the one and only fix that i have got so far and works wonders .

funkyjamma's avatar

@Lazyy it works right off setting up a new app now. This was a bug very specific to when it first came out.

raduP85's avatar

I struggled to bootstrap Tailwind CSS 4 (TW4) in a fresh Laravel 12 project using Blade templating, as the official Tailwind docs focus on SPA setups (React, Vue, etc.), and Laravel’s default Vite integration is tailored for Tailwind CSS 3 (TW3). Specifically, the laravel-vite-plugin and @vite directive rely on TW3’s PostCSS workflow, pulling in unnecessary dependencies like postcss, tailwindcss, and autoprefixer, and causing asset path issues (e.g., url(/assets/...) breaking in production). My solution was to drop all TW3-related packages, install TW4’s @tailwindcss/vite plugin, and create a custom ViteServiceProvider to replace laravel-vite-plugin’s functionality. This approach eliminates PostCSS, ensures TW4 compatibility, and uses base: './' in vite.config.js for portable asset paths (e.g., url(./...)) that work on subdomains (e.g., sub.example.com) or subfolders. Below are the steps and code to make it work seamlessly.

  1. Remove TW3 Packages:
npm uninstall laravel-vite-plugin tailwindcss postcss autoprefixer

Delete postcss.config.js if present.

  1. Install TW4:
npm install @tailwindcss/vite
  1. Configure Vite: Update vite.config.js to use @tailwindcss/vite, set base: './' for relative asset paths, and add a Blade hot-reload plugin.
  1. Create ViteServiceProvider:
php artisan make:provider ViteServiceProvider

Define a custom @vite directive to load assets from public/build/.vite/manifest.json in production or Vite’s dev server in development.

  1. Check if the new is registered in Register Provider: Add App\Providers\ViteServiceProvider::class to bootstrap/providers.php.
  2. Check the @vite() directive in the template file
@vite(['resources/css/app.css', 'resources/js/app.js'])

7.Set Up CSS with the new Tailwind 4 directive: In resources/css/app.css (remove the old tw3)

@import "tailwindcss";
  1. Test dev don't forget to clear cache, clear config, clear view
php artisan cache:clear
php artisan config:clear
php artisan view:clear
composer run dev
  1. Test production change the .env variable to production
APP_ENV=production

build production assets

npm run build

start the laravel server without vite server

php artisan serve

This setup eliminates PostCSS bloat, simplifies TW4 integration, and supports Blade templating with flexible asset paths. Hope this helps others facing the same issue!

Snapey's avatar

I just follow the cli instructions and dont get involved with vite at all. Simple as...

Please or to participate in this conversation.