Skip to content
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

Tailwind CSS 4.0.8 not loading correctly #3374

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

Tailwind CSS 4.0.8 not loading correctly #3374

alapeta opened this issue Feb 21, 2025 · 44 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"
  }

@benjamincanac
Copy link
Member

So I did the update to tailwindcss@4.0.8 (the docs is running it): #3373.

In the next 3.0.0-alpha.14 release the sources will be correctly configured so you will only have to update the @import "tailwindcss"; to @import "tailwindcss" theme(static);. I didn't find a way to make it work without this yet but this will have exactly the same behavior as before with 4.0.7.

@bennyzen
Copy link

ERROR Pre-transform error: Files imported with @import "…" theme(…) must only contain @theme blocks. 3:21:06 PM
Plugin: @tailwindcss/vite:generate:serve

Strange, I get the error above.

Copy link
Member

@bennyzen The @import "tailwindcss" theme(static); only works with tailwindcss@4.0.8, it has been introduced in tailwindlabs/tailwindcss#16514

@bennyzen
Copy link

To make sure I really have 4.0.8, I've deleted node_modules and changed the override to pin that version. Now the error is gone, but the style is broken again.

Thank you, but I'll switch back to 4.0.7 and wait until we have 3.0.0-alpha.14 with a working fix. Good enough for me atm.

@StirStudios
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

To be clear this does not fully resolve the situation. It looks like it does but it does not. Most of the theming comes back but certain aspects like a carousel do not work.

Hopefully we get a new fix soon @benjamincanac

Copy link
Member

@StirStudios As mentioned above, this has been fixed inside https://github.com/nuxt/ui/pull/3373/files. This is why my advice was to stick with 4.0.7 as resolution until we release alpha.14.

@projct1
Copy link

projct1 commented Feb 26, 2025

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.

Where i need to write this?

@stefanisarie
Copy link

@projct1 you need to write that in your package.json.

@maximepvrt maximepvrt mentioned this issue Feb 26, 2025
28 tasks
@bansal
Copy link

bansal commented Feb 27, 2025

This package.json is working

{
  "name": "nuxt-app",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare",
    "lint": "eslint .",
    "lint:fix": "eslint --fix ."
  },
  "dependencies": {
    "@iconify-json/lucide": "^1.2.26",
    "@iconify-json/simple-icons": "^1.2.26",
    "@nuxt/ui": "3.0.0-alpha.13",
    "nuxt": "^3.15.4"
  },
  "devDependencies": {
    "@nuxt/eslint": "^1.1.0",
    "eslint": "^9.21.0",
    "typescript": "^5.7.3"
  },
  "overrides": {
    "tailwindcss": "4.0.7",
    "@tailwindcss/node": "4.0.7",
    "@tailwindcss/postcss": "4.0.7",
    "@tailwindcss/vite": "4.0.7"
  },
  "resolutions": {
    "tailwindcss": "4.0.7",
    "@tailwindcss/postcss": "4.0.7",
    "@tailwindcss/vite": "4.0.7"
  }
}

@anton-liam
Copy link

Still not work, when will 3.0.0-alpha.14 release

@IsraelOrtuno
Copy link
Contributor

@anton-liam

Still not work, when will 3.0.0-alpha.14 release

3.0.0-alpha.14 has not been released yet

@benjamincanac
Copy link
Member

You can now use 3.0.0-beta.1, do note that you still need to use @import "tailwindcss" theme(static); but you can now remove the tailwindcss@4.0.7 resolutions.

@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
│ │ └─nuxt.config.ts          <-- imports the '@nuxt/ui' module
│ ├─another-layer
│ └─...
└─nuxt.config.ts              <-- extends layers/core

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?

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