Skip to content

Tailwind CSS 4.0.8 not loading correctly #3374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alapeta opened this issue Feb 21, 2025 · 56 comments
Closed

Tailwind CSS 4.0.8 not loading correctly #3374

alapeta opened this issue Feb 21, 2025 · 56 comments
Labels
bug Something isn't working upstream v3 #1289

Comments

@alapeta
Copy link

alapeta commented Feb 21, 2025

Environment

  • Mac OS
  • Node version v20.18.1
  • Nuxt v3.15.4

Is this bug related to Nuxt or Vue?

Nuxt

Version

v3.0.0-alpha13

Reproduction

  1. follow installation from guide:

npx nuxi init -t ui3

  1. start: npm run dev

Description

There are no colors, no buttons, no borders, no tailwind classes...

Image

I am not sure what happened and when. Just discovered today after cleaning node_modules and reinstalling all packages that tailwind is not loaded correctly.

As you can see the same is for fresh install from provided starter.

Additional context

No response

Logs

@alapeta alapeta added bug Something isn't working triage v3 #1289 labels Feb 21, 2025
@WillGyt
Copy link

WillGyt commented Feb 21, 2025

Did a bit of digging and the issue seems to be coming from this commit.
For some reason styles work with tailwind version 4.0.0-beta.9 but not version 4.0.0

@alapeta
Copy link
Author

alapeta commented Feb 21, 2025

@WillGyt
going back to 4.0.0-beta.9 did not solve the issue for me :-(

My current package.json for Starter project:

"dependencies": {
"@iconify-json/lucide": "^1.2.26",
"@iconify-json/simple-icons": "^1.2.25",
"tailwindcss": "4.0.0-beta.9",
"@tailwindcss/postcss": "4.0.0-beta.9",
"@tailwindcss/vite": "4.0.0-beta.9",
"@nuxt/ui": "^3.0.0-alpha.12",
"nuxt": "^3.15.4"
},
"devDependencies": {
"@nuxt/eslint": "^1.1.0",
"eslint": "^9.20.1",
"typescript": "^5.7.3"
}

Still no styles...

@StirStudios
Copy link

StirStudios commented Feb 21, 2025

It seems there is a regression with the latest update of Tailwind 4.0.8 (dropped 2hrs ago).
https://github.com/tailwindlabs/tailwindcss/releases/tag/v4.0.8

Key changes for this issue are here:

Changed
Don't include theme variables that aren't used in compiled CSS (tailwindlabs/tailwindcss#16211, tailwindlabs/tailwindcss#16676)


This happened to us before and was resolved: #3275 @benjamincanac @WillGyt @alapeta

However it seems the same workaround still works for now:

Replace

@import 'tailwindcss';
@import '@nuxt/ui';

with

@layer theme, base, components, utilities;

@import 'tailwindcss/theme' layer(theme) theme(static);
@import 'tailwindcss/preflight' layer(base);
@import 'tailwindcss/utilities' layer(utilities);

/* Then import "@nuxt/ui": */
@import '@nuxt/ui';

@StirStudios
Copy link

Looking into this further the above workaround only partially helped. I went back to my original solution which was to set the pnpm manager like so:

 "pnpm": {
    "overrides": {
      "tailwindcss": "4.0.7",
      "@tailwindcss/node": "4.0.7",
      "@tailwindcss/postcss": "4.0.7",
      "@tailwindcss/vite": "4.0.7"
    }
  }

This will bring everything back to the last working version.

@WillGyt
Copy link

WillGyt commented Feb 21, 2025

@StirStudios This worked, thanks so much.

@alapeta
Copy link
Author

alapeta commented Feb 21, 2025

This workaround works for me also - both for Starter and my own project.
Thanks a lot @StirStudios 😃.

@schillerenrico
Copy link

yeah tailwind 4.0.8 breaks the current style import with the workaround, using 4.0.7 until fix comes out

@sandros94 sandros94 added upstream and removed triage labels Feb 22, 2025
@sandros94
Copy link
Member

sandros94 commented Feb 22, 2025

Indeed there has been a regression upstream. Fastest workaround, as suggested, is to pin 4.0.7 in your package.json via:

  "resolutions": {
    "tailwindcss": "4.0.7",
    "@tailwindcss/postcss": "4.0.7",
    "@tailwindcss/vite": "4.0.7"
  }

@stefanisarie
Copy link

@StirStudios thank you for the workaround, it worked for me too!

@meikuv
Copy link

meikuv commented Feb 23, 2025

@StirStudios thank you, it worked

@Dwhyte
Copy link

Dwhyte commented Feb 23, 2025

@StirStudios that worked for me as well. Just this alone did it. Thank you.

@TheBigO
Copy link

TheBigO commented Feb 23, 2025

@StirStudios - thanks for the help. For anyone still struggling, I was able to get "3.0.0.-alpha13" working by manually installing "tailwindcss", "@tailwindcss/postcss", and "@tailwindcss/vite" (all 4.0.7).

"dependencies": {
"@nuxt/ui-pro": "^3.0.0-alpha.13",
"@tailwindcss/postcss": "^4.0.7",
"@tailwindcss/vite": "^4.0.7",
"nuxt": "^3.15.2",
"tailwindcss": "^4.0.7",
"vue": "latest",
"vue-router": "latest"
}

@alapeta
Copy link
Author

alapeta commented Feb 23, 2025

My few cents @TheBigO: you should rather follow solution provided by @sandros94.
The problem is not related to nuxt/ui 3.0.0-alpha.13.
It is related to tailwind 4.0.8.
Your package.json will install 4.0.8 (latest version) on fresh install as you do not fix the Tailwind resolution to 4.0.7

@TheBigO
Copy link

TheBigO commented Feb 23, 2025

My few cents @TheBigO: you should rather follow solution provided by @sandros94. The problem is not related to nuxt/ui 3.0.0-alpha.13. It is related to tailwind 4.0.8. Your package.json will install 4.0.8 (latest version) on fresh install as you do not fix the Tailwind resolution to 4.0.7

That makes sense @alapeta - thanks for the additional information.

@jeannen
Copy link

jeannen commented Feb 24, 2025

Solution for those using NPM:

Add this to your package.json, then run npm i

"overrides": {
    "tailwindcss": "4.0.7",
    "@tailwindcss/postcss": "4.0.7",
    "@tailwindcss/vite": "4.0.7"
}

@sandros94 sandros94 marked this as a duplicate of #3386 Feb 24, 2025
@tesla3327
Copy link

In case anyone is searching for this, pnpm uses a slightly different structure for overrides:

  "pnpm": {
    "overrides": {
      "tailwindcss": "4.0.7",
      "@tailwindcss/postcss": "4.0.7",
      "@tailwindcss/vite": "4.0.7"
    }
  },

@benjamincanac benjamincanac pinned this issue Feb 24, 2025
@benjamincanac benjamincanac changed the title Tailwind not loading correctly Tailwind CSS 4.0.8 not loading correctly Feb 24, 2025
@benjamincanac
Copy link
Member

So the situation is a bit worst than the tailwindcss@4.0.5 update (#3275) because on top of the stripped CSS variables which can be fixed doing:

@import "tailwindcss" theme(static);
@import "@nuxt/ui";

We now have to explicitly register sources using the @source directive: tailwindlabs/tailwindcss#16733 (comment)

I'll try to find a way to do this within @nuxt/ui but in the meantime it's best to set the resolution to 4.0.7.

@mshornikov
Copy link

This one solved the issue for me

assets/css/main.css

@import 'tailwindcss' theme(static);
@import '@nuxt/ui';
@source '../../node_modules/@nuxt/ui/.nuxt';

I am using: pnpm10.4.1, @nuxt/ui@3.0.0-alpha.13, tailwindcss@4.0.8

@arslan-butt
Copy link

For bun (overrides in package.json)

"overrides": {
    "tailwindcss": "4.0.7",
    "@tailwindcss/postcss": "4.0.7",
    "@tailwindcss/vite": "4.0.7"
  }

@yschroe
Copy link

yschroe commented Feb 28, 2025

Anyone else has an issue now with missing classes in the final CSS when they are only defined in the app.config.ts? E.g. if I use 'bg-orange-500' to style the default background of the header of the UCard component, the header background is just white. If I then apply 'bg-orange-500' to any other component directly, the new class is picked up and my headers are now styled as well.

I am using 3.0.0-beta.2 with tailwind@4.0.9.

@benjamincanac
Copy link
Member

@yschroe Did you import Tailwind CSS like this: @import "tailwindcss" theme(static);?

@yschroe
Copy link

yschroe commented Feb 28, 2025

Yes, I imported it with theme(static). The basic out-of-the-box styles from nuxt UI are applied and working fine, but if I add a class to app.config.ts that only appears in there, it is not picked up even after a dev server restart.

Edit after seeing StirStudios response: I am using Nuxt layers as well and my app.config.ts is placed inside a Nuxt layer folder.

@StirStudios
Copy link

StirStudios commented Feb 28, 2025

@benjamincanac @yschroe we can confirm that certain classes are missing for us as well.

That said, when we run our Nuxt Layer project in solo mode (not inside a root app), everything works correctly. However, as soon as we use it as a layer inside a root app, some classes are lost.

Up until now, we’ve been able to share app.config.ts between the layer and the root project—same with main.css. In other words, whatever is set in the layer has been inherited by the root app. However, many classes are now lost unless we explicitly copy app.config.ts to the root app. Previously, these classes were inherited automatically.

Additionally, we have a safelist.txt file to help retain certain classes. This has helped restore some classes that were not caught in app.config.ts.

The missing classes seem to include:

-translate-y-full
-translate-y-96
focus:translate-y-0
md:basis-1/6
md:block
md:hidden
mx-1
leading-relaxed

Overriding a container is not inherited or can it be set from the root app. No matter what we do we cannot get this to work.

:root {
  --ui-container: var(--container-8xl);
}

@theme static {
  --container-8xl: 96rem;
}

All of these classes are defined inside app.config.ts.

Prior to the Nuxt UI 3 beta and Tailwind CSS 4.0.7, these classes were inherited correctly and were not missing.

We are able to update to Nuxt UI 3.0.0-beta.2, while keep tailwind at 4.0.7 and everything works as usual.

Close but not fixed from our eyes.

Copy link
Member

This whole thing is due to Tailwind CSS changes in 4.0.8, since they don't use module graph anymore we need to specify each source, so you have to @source your layers as well.

@StirStudios
Copy link

@benjamincanac @yschroe thanks for the tips now solved for us.

@yschroe if you need any help this is what we needed to do inside our root app main.css

@source '../../../node_modules/@stir/base';

Once you have that it just works!

@wherewasitv
Copy link

wherewasitv commented Mar 1, 2025

Sorry folk, running into some issues and found this thread.
Not sure what parts of above I need to know yet, cos I have other issues...

Image

Why is this brand new project displaying an error on theme(static), when it doesn't on your projects?
I had to change from @apply to @reference to avoid the error Cannot apply unknown utility class, but the TW styles do not work anyway?

Using Tailwind classes directly on an element do work though.

Image

Image

These are my packages currently:

Image

This is my configuration:

// https://nuxt.com/docs/api/configuration/nuxt-config
import removeConsole from "vite-plugin-remove-console";
import tailwindcss from "@tailwindcss/vite";
export default defineNuxtConfig({
	compatibilityDate: "2024-11-01",
	devtools: { enabled: true },
	modules: ["@pinia/nuxt", "@pinia/colada-nuxt", "@nuxtjs/supabase", "dayjs-nuxt", "@vueuse/nuxt", "@nuxt/ui-pro"],
	components: {
		global: true,
		dirs: ["~/components"],
	},
	ssr: false,
	app: {
		head: {
			charset: "utf-8",
			viewport: "width=device-width, initial-scale=1",
		},
	},
	supabase: {
		// options: https://supabase.nuxtjs.org/get-started#options
		url: process.env.SUPABASE_URL,
		key: process.env.SUPABASE_KEY,
		//serviceKey: process.env.SUPABASE_SERVICE_KEY,
		redirect: false,
		redirectOptions: {
			login: "/login",
			callback: "/confirm",
			exclude: [],
		},
	},
	css: ["@/assets/css/main.css"],
	//css: ["@/assets/scss/main.scss"],
	vite: {
		define: {
			__VUE_PROD_DEVTOOLS__: process.env.ENVIRONMENT !== "prod",
		},
		/* css: {
			preprocessorOptions: {
				scss: {
					additionalData: '@use "@/assets/scss/_variables.scss" as *; @use "@/assets/scss/_mixins.scss" as *;',
				},
			},
		}, */
		plugins: [tailwindcss(), removeConsole()],
	},
	runtimeConfig: {
		public: {
			supabaseUrl: process.env.SUPABASE_URL,
			supabaseKey: process.env.SUPABASE_KEY,
			environment: process.env.ENVIRONMENT,
		},
	},
});

You'll see the bits I've commented relate to SCSS compilation. I've spent an afternoon on this and I just cannot get Nuxt UI Pro v3 working with SCSS files, and I cannot get Tailwind styles applying within a basic CSS file. NOTE: I have removed some packages in the process like PostCSS stuff for example.

It'd be great if there was a guide in the docs for at least SCSS compilation as that seems like a common use case. Happy to contribute it myself, when I find out how to 😆

This is proving harder than it should be, or should I revert to 1.7 until 3 is more stable? (not that this threads issue was Nuxt UIs fault)

@StirStudios
Copy link

@wherewasitv

I can see you have not removed the overrides as that will cause things to break.

Remove this from your package.

"overrides": t
"tailwindcss": "4.0.7",
"@tailwindess/vite": "^4.0.7"

Also remove this from your main.css

@source '../../node_modules/@nuxt/ui/.nuxt';

Run this command to clear things out

rm pnpm-lock.yaml && rm -rf node_modules && pnpm store prune && pnpm i

Then your project should work correctly using Tailwindcss 4.0.9 along with Nuxt UI 3beta

@wherewasitv
Copy link

@StirStudios - Ahh yip, that's re-aligned to 4.0.9 now, thx 👍

Still cannot apply the TW styles to my custom classes, but I think that might be another TW v4 issue.

@StirStudios
Copy link

I would suspect the issue is including the source of each file as that is what as occurred since TW 4.0.8.

@wherewasitv
Copy link

The upgrade guide says you need to do that for CSS files outside your main.css file (if I read that correctly), yet custom classes in my main.css file are not applying their TW utility class styles. Hmmm... I'll keep digging.

I'm also new to Tailwind so I prolly just need to get familiar with how TW does things (esp. with v4 cos all the docs and articles out there now reference v3 stuff mostly). Then I just need to find a Nuxt3/TW4 example to get my SCSS compiling.

@StirStudios
Copy link

@yschroe
Copy link

yschroe commented Mar 1, 2025

This whole thing is due to Tailwind CSS changes in 4.0.8, since they don't use module graph anymore we need to specify each source, so you have to @source your layers as well.

Thanks, with manually adding the sources my project now work as before. 👍

I also noticed that not only the classes of my app.config.ts were missing before but all classes defined in any of my layers. It is still not clear to me which folders are scanned by default. My project structure looks like this:

root/
├─app/
├─layers/ 
│ ├─core
| | ├─assets/css/main.css     <-- imports tailwindcss
| | ├─app.config.ts           <-- overrides a few styles of Nuxt UI
│ │ └─nuxt.config.ts          <-- imports the '@nuxt/ui' module
│ ├─another-layer
│ └─...
└─nuxt.config.ts              <-- extends layers/core; uses nuxt compatibility v4

The tailwind docs state that the starting point for scanning the files is the current working directory. If I start the app out of my root folder isn't /root the current working directory and the classes in all subfolders should be picked up automatically, including the /layers folder? By default only the /app folder is scanned though and I need to add @source "../../../../layers"; to my main.css in order for it to work. Is this a bug or is this the intended way with tailwind ^4.0.8?

@leeovery
Copy link

leeovery commented Mar 1, 2025

Is anyone else seeing issues with custom colors with Nuxt UI 3 after following this fix?

Im adding the custom colours in the way the docs suggest but its creating a cyclical set of css vars where NuxtUI is overwriting the TW vars but then still referencing the TW vars as values to its own vars 🤪

Image

Image

Image

Update:

Seems you cant call the color alias the same as the color itself. I suspect this is a bug. Ill report separately.

@StirStudios
Copy link

This whole thing is due to Tailwind CSS changes in 4.0.8, since they don't use module graph anymore we need to specify each source, so you have to @source your layers as well.

Thanks, with manually adding the sources my project now work as before. 👍

I also noticed that not only the classes of my app.config.ts were missing before but all classes defined in any of my layers. It is still not clear to me which folders are scanned by default. My project structure looks like this:

root/
├─app/
├─layers/ 
│ ├─core
| | ├─assets/css/main.css     <-- imports tailwindcss
| | ├─app.config.ts           <-- overrides a few styles of Nuxt UI
│ │ └─nuxt.config.ts          <-- imports the '@nuxt/ui' module
│ ├─another-layer
│ └─...
└─nuxt.config.ts              <-- extends layers/core; uses nuxt compatibility v4

The tailwind docs state that the starting point for scanning the files is the current working directory. If I start the app out of my root folder isn't /root the current working directory and the classes in all subfolders should be picked up automatically, including the /layers folder? By default only the /app folder is scanned though and I need to add @source "../../../../layers"; to my main.css in order for it to work. Is this a bug or is this the intended way with tailwind ^4.0.8?

That is the suggested way so you are doing things correctly!

https://tailwindcss.com/docs/detecting-classes-in-source-files

@StirStudios
Copy link

Is anyone else seeing issues with custom colors with Nuxt UI 3 after following this fix?

Im adding the custom colours in the way the docs suggest but its creating a cyclical set of css vars where NuxtUI is overwriting the TW vars but then still referencing the TW vars as values to its own vars 🤪

Image

Image

Image

Update:

Seems you cant call the color alias the same as the color itself. I suspect this is a bug. Ill report separately.

Not sure if this helps but once you have defined your colors you ran then setup the root like so:

:root {
--ui-primary: var(--ui-color-primary-500);
}

You can also define your custom color in app config or nuxt config and NuxtUI will generate the alias:

https://ui3.nuxt.dev/getting-started/theme

Check the colors section.

@wherewasitv
Copy link

wherewasitv commented Mar 1, 2025

I've got things working - mostly - thanks for nudges in the right direction @StirStudios

I still have one oddity which I cannot explain. The tailwind import statement in my main.css file syntax errors:

Image

Not sure if it's helpful but just in case, each underline shows these two errors:

Image
then

Image

Now, to further confuse things, in my searching for an answer, the following is causing is happening...

With the theme(static) import the Nuxt UI theme appears to be working:

Image

But, a little Chat GPT'ing brought up this gem (i.e. always a tad skeptical):

Image

No matter what I do configuration wise in nuxt.config or app.config the Nuxt UI 'theme' is not set or works...

Image

Is that info even valid (because I see you all still defining the static theme), or is it correct but I'm missing some configuration or key info to get it working?

UPDATE: Yeeaahh that Chat GPT result feels like some classic disinformation 😆 , restoring the theme import (even with the errors) works including light/dark mode switching. Hmm.

Copy link
Member

@wherewasitv You probably have a version of tailwindcss < 4.0.8, you should remove any tailwindcss resolutions and refresh your deps. You can check in your lockfile to see which version is used.

@wherewasitv
Copy link

@benjamincanac - Version is 4.0.9 and I cleared out the resolutions a couple of posts ago.

@StirStudios
Copy link

I've got things working - mostly - thanks for nudges in the right direction @StirStudios

I still have one oddity which I cannot explain. The tailwind import statement in my main.css file syntax errors:

Image

Not sure if it's helpful but just in case, each underline shows these two errors:

Image then

Image

Now, to further confuse things, in my searching for an answer, the following is causing is happening...

With the theme(static) import the Nuxt UI theme appears to be working:

Image

But, a little Chat GPT'ing brought up this gem (i.e. always a tad skeptical):

Image

No matter what I do configuration wise in nuxt.config or app.config the Nuxt UI 'theme' is not set or works...

Image

Is that info even valid (because I see you all still defining the static theme), or is it correct but I'm missing some configuration or key info to get it working?

UPDATE: Yeeaahh that Chat GPT result feels like some classic disinformation 😆 , restoring the theme import (even with the errors) works including light/dark mode switching. Hmm.

Static is correct, not sure why you are getting a syntax issue though.

Also for your theme layer you need to add static as well.

@import 'tailwindcss' theme(static);

@theme static {
  --font-sans: 'InterVariable', system-ui, sans-serif;

  --container-8xl: 96rem;

  --color-white: #ffffff;
  --color-black: #14161a;
}

@wherewasitv
Copy link

wherewasitv commented Mar 2, 2025

Yeah I added the @theme static in the hope that was the reason but no dice.
Confirmed that it is a Linting issue though, just gotta track down the config for it.

To resolve this I installed npm install -D stylelint stylelint-config-standard with the following config:

// stylelint.config.js
module.exports = {
	extends: [ "stylelint-config-standard" ],
	rules: {
		"at-rule-no-unknown": [
			true,
			{
				ignoreAtRules: [
					"tailwind",
					"apply",
					"variants",
					"responsive",
					"screen",
				],
			},
		],
		"declaration-block-trailing-semicolon": null,
		"no-descending-specificity": null,
	},
};

And I disabled the standard CSS, LESS, and SCSS validation in vsCode's settings e.g.

// setting.json
"css.validate": false,
"less.validate": false,
"scss.validate": false,

@sandros94
Copy link
Member

@wherewasitv by the screenshots its seems that your main.css isn't associated to tailwind, this might be the reason why you see the syntax issue.

Follow docs and edit your settings.jsonby adding:

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

@BlackDahlia313
Copy link

It seems there is a regression with the latest update of Tailwind 4.0.8 (dropped 2hrs ago). https://github.com/tailwindlabs/tailwindcss/releases/tag/v4.0.8

Key changes for this issue are here:

Changed
Don't include theme variables that aren't used in compiled CSS (tailwindlabs/tailwindcss#16211, tailwindlabs/tailwindcss#16676)

This happened to us before and was resolved: #3275 @benjamincanac @WillGyt @alapeta

However it seems the same workaround still works for now:

Replace

@import 'tailwindcss';
@import '@nuxt/ui';

with

@layer theme, base, components, utilities;

@import 'tailwindcss/theme' layer(theme) theme(static);
@import 'tailwindcss/preflight' layer(base);
@import 'tailwindcss/utilities' layer(utilities);

/* Then import "@nuxt/ui": */
@import '@nuxt/ui';

this worked for me. ty

@alexcroox
Copy link

I've just migrated from Nuxt UI 2 to 3 and suffering the same issue with missing css variables

Image

Lockfile shows tailwind at 4.0.14, UI Pro at 3.0.0

css/index.css is:

@import 'tailwindcss' theme(static);
@import '@nuxt/ui-pro';

@theme static {
  --font-sans: 'Open Sans', sans-serif;

  --color-green-50: #EFFDF5;
  --color-green-100: #D9FBE8;
  --color-green-200: #B3F5D1;
  --color-green-300: #75EDAE;
  --color-green-400: #00DC82;
  --color-green-500: #00C16A;
  --color-green-600: #00A155;
  --color-green-700: #007F45;
  --color-green-800: #016538;
  --color-green-900: #0A5331;
  --color-green-950: #052E16;
}

@Soabirw
Copy link

Soabirw commented Mar 14, 2025

I had a simple use case. Inside an index.vue file:

<img :src="post.meta.thumbImage" :alt="post.meta.title" class="w-32 h-32 object-cover mr-4" />

None of those classes made it into the production build.

Changing my build script to npm and adding this, from a tip above, did solve it. So it does seem to be something introduced in later versions of Tailwind.

"resolutions": {
    "tailwindcss": "4.0.7",
    "@tailwindcss/postcss": "4.0.7",
    "@tailwindcss/vite": "4.0.7"
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream v3 #1289
Projects
None yet
Development

No branches or pull requests