Tailwind v4 and DaisyUI

Hi all,

I followed the cookbook Kirby meets Tailwind CSS | Kirby CMS.

Installing Tailwind with npm install tailwindcss@latest leads to this error:

mat@macbook kirbyproject % npm run watch            
> watch
> npx tailwindcss -i ./src/css/tailwind.css -o ./assets/css/styles.css -w

npm error could not determine executable to run

This problem disappears with the previous version of Tailwind : npm install tailwindcss@3.4.17

Is there an easy way to get v4 up and running?


Then I tried to install DaisyUI, but the styles are not taken into account.
Do you know what I am doing wrong? Thanks a lot.

Here is what I did :

npm install daisyui@latest

tailwind.config.js

module.exports = {
  content: [
    './site/**/*.php',
    './site/**/*.html',
    './src/js/**/*.js',
  ],
  theme: {
    extend: {},
  },
  plugins: [
    require('daisyui'),
  ],
};

package.json

{
    "name": "projectname",
    "scripts": {
        "watch": "npx tailwindcss -i ./src/css/tailwind.css -o ./assets/css/styles.css -w",
        "build": "npx tailwindcss -i ./src/css/tailwind.css -o ./assets/css/styles.css -m"
    },
    "dependencies": {
        "daisyui": "^5.0.43",
        "tailwindcss": "^3.4.17"
    }
}

src/css/tailwind.css

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

Yes, the cookbook doesn’t work with Tailwind 4 anymore. You’d have to follow this guide: Tailwind CLI - Tailwind CSS

Also, do not use the JS config for Tailwind 4, but only the tailwindcss, as specified in the guide on the linked Tailwind page.

1 Like
// style.css
// source can also be empty to scan "all"
@import "tailwindcss" source("../site/**/*.{html,js,php}");
@plugin "daisyui";
// @plugin "@tailwindcss/typography";

Like @tobimori said, the building process is a bit different because there is no config.tailwind.js file anymore, but the building process is actually more simple and fast.

// script from package.json (e.g.)
    "build:watch": "npx @tailwindcss/cli -i styles.css -o public/assets/css/main.css --watch --minify",

Obviously you would have to install tailwindcss as well as daisy-ui first.

1 Like

Thanks, it worked !

Hello All,

Sorry to jump into a thread not created by me, but I just jumped to Kirby (Starter pack) and tried to install Tailwind 4 and DaisyUi (same as the OP). Unfortunately, it didn’t work very well for me :slight_smile:

I got an error message in the browser inspector (attached). This is how my assets/css/style.css looks:

@import "tailwindcss" source("./site/**/*.{html,js,php}");
@plugin "daisyui" {
  themes: light --default, dark --prefersdark;
  root: ":root";
  include: ;
  exclude: ;
  prefix: ;
  logs: true;
}
@plugin "@tailwindcss/typography";

This is the package.json:

{
  "name": "2aq",
  "scripts": {
    "build:watch": "npx @tailwindcss/cli -i ./src/input.css -o ./src/output.css --watch --minify"
  },
  "dependencies": {
    "@tailwindcss/cli": "^4.1.12",
    "tailwindcss": "^4.1.12"
  },
  "devDependencies": {
    "daisyui": "^5.1.6"
  }
}

header.php

<?php

?>
<!DOCTYPE html>
<html lang="en">
<head>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">

  <?php
  /*
    In the title tag we show the title of our
    site and the title of the current page
  */
  ?>
  <title><?= $site->title()->esc() ?> | <?= $page->title()->esc() ?></title>

  <?php

  ?>
  <?= css([
    'assets/css/prism.css',
    'assets/css/lightbox.css',
    'assets/css/index.css',
    'assets/css/style.css',
    'src/output.css',
    '@auto'
  ]) ?>

  <?php

  ?>
  <link rel="shortcut icon" type="image/x-icon" href="<?= url('favicon.ico') ?>">
</head>

Any idea what I messed up? (I am using Kirby v5)

I did some changes and maybe it works now …
I removed some parts from the original Kirby cookbook tutorial (Kirby meets Tailwind CSS):

I removed tailwind.config.js and also src/css/tailwind.css
In the /src folder, I left only input.css & output.css

Changed assets/css/styles.css to this:

/*! tailwindcss v4.1.12 | MIT License | https://tailwindcss.com */
@plugin "daisyui" {
  themes:
    garden --default,
    dark --prefersdark;
  root: ":root";
  include:;
  exclude:;
  prefix:;
  logs: true;
}
@layer properties;
.collapse {
  visibility: collapse;
}
...

package.json to this:

{
  "name": "2aq",
  "scripts": {
    "build:watch": "npx @tailwindcss/cli -i ./assets/css/styles.css -o ./src/output.css --content './site/**/*.php' --watch --minify"
  },
  "dependencies": {
    "@tailwindcss/cli": "^4.1.12",
    "@tailwindcss/upgrade": "^4.1.12",
    "tailwindcss": "^4.1.12"
  },
  "devDependencies": {
    "daisyui": "^5.1.6"
  }
}

site/snippets/header.php to this:

 <?= css([
    'assets/css/prism.css',
    'assets/css/lightbox.css',
    'assets/css/index.css',
    'assets/css/styles.css',
    '@auto'
  ]) ?>

The 404 error message that tailwindcss is missing disappeared but I would appreciate it if someone more experienced could confirm that the changes are OK.

doesn’t look to work. Can’t apply any Tailwind or DaisyUI styles. Any other ideas?

  1. You are no longer importing your output.css in your header.

    2. You seem to be missing the first ( and must be first ) tailwind import.

This is an abbreviated sample of my tailwind4 css

@import "tailwindcss";

/* blueprints have TW selectors */
@source "../../../public/content/";

/* the php files */
@source "../../site/";

/* some extra css */
@import "../../../node_modules/lenis/dist/lenis.css";

@theme {
  /* utopia vars */
  @import "./utopia/utopia-post.css";
  --color-*: initial;
  --padding: var(--spacing-4-m);
  --leading-small: 1;
  --leading-base: 1.364;
  --blur: 10px;
  --radius-lg: 0 var(--spacing-2);
  --font-base: 'National', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

/* ... more  */

}

@layer base {

  h1 {
    font-size: var(--text-4xl);
    font-family: var(--head-font);
    line-height: var(--leading-mid);
  }

/* etc...*/

}

As you can see I have added external css in the theme section. You don’t need js any more.
If Daisy UI can give you plain css. Just import it. TW4 is much simpler than 3

Thank you @oyster :slight_smile:

Hmm actually, it might work now. Fixed what you suggested, and it looks like I can apply Tailwind styling.

Hopefully, DaisyUI will work too.

Do you think I also need to add source to /assets/css/style.css like in my first post:

@import "tailwindcss" source("./site/**/*.{html,js,php}");

Ok it was too early to get excited :slight_smile: now the previous 404 error message returned back:

Something looks wrong here. The files that contain your @import statements are the input files (-i) and should be in the src folder. Whatever you call the result of the build process css file (-o) should end up in the assets/css folder. Then the files in the assets folder should be loaded in your head. If I understand the bits and pieces you posted so far correctly, you are doing it the wrong way round.

1 Like

Thank you @texnixe Yes, I have the same feeling that I totally messed up the order of the files.

Ok maybe I have to start from scratch … The import statement is in my assets/css/styles.css –> will move this file to src/styles.css.

The output.css file is located in src/ –> will move it to assets/css/output.css

In the head part I will remove styles.css and add only output.css

Then in package.json I will change the build/watch script to:

"build:watch": "npx @tailwindcss/cli -i ./src/styles.css -o ./assets/css/output.css --content './site/**/*.php' --watch --minify"

How it sound to you? :neutral_face:

Good!

1 Like

This didn’t work for me. Something about that syntax in my setup kept throwing errors.
So i use the @sourcesource syntax. Tailwind CLI reads everything not listed in .gitignore as text so It has no use of the .extensio@source The @source directive overrides the default TW source setting.

So if you permit the site folder in .gitignore you shouldn’t need to specify source at all.
I see that you are specifying –content in your npm cli command. Do one or the other. Not both.

I see from DaisyUI that they use all directives in the css not CLI.

I think the original Kirby post is probably outdated.

1 Like

Thank you @oyster I think after the changes I made in my previous post as a reply to Sonja , Tailwind is working.

It would be nice to have an updated tutorial, though, as the current one is probably working with Tailwind v3. :slight_smile:

Yeah. Probably a full time job reviewing this content. Probably they should append these posts with currency meta-data in a footer. ie Dev enviro : [ K4 + , TW3 , php8.x ].

All this explores any thin wall between content and style in the blueprint space.
I think the Kirby crew have addressed this well with default block overrides and extendable layout hooks.

1 Like

I’ve updated the recipe for Tailwind CSS v4. I didn’t include information about adding DaisyUI specifically, but that should be pretty straight forward. Please take a look:

2 Likes