Tailwind classes from a shared package are missing in a monorepo app
Tailwind classes work in the app but not in components from a shared packageShort answer
Tailwind generates CSS only for class names it finds while scanning files. In a monorepo, a shared package is often reached through node_modules or sits outside the folder Tailwind starts from, so its classes are never seen. Register that folder with @source, and set the base path with source() if builds start at the repo root.
Fix it fast
1Find out which cause you have
Pick a class that only appears in the shared package and search the built CSS for it. If it is absent, the scanner never saw that file.
npx next build grep -rl "your-unique-class" .next/static/css | head2Match what you see, then jump to its fix
- 1
Components from packages/ui have no styling; the same classes work when used directly in the appThe shared package is ignored by automatic detectionFix - 2
It works when you run the app from its own folder but fails when a workspace command runs from the repo rootTailwind starts from the wrong base folderFix - 3
Only some variants of a component are missing, for example color-based onesClass names are assembled from stringsFix
- 1
What does the error look like?
Tailwind classes work in the app but not in components from a shared packageStyles missing only after next build or only in one app of the monorepo
Cause 1 of 3
The shared package is ignored by automatic detection
1Check
Tailwind scans project files but skips anything in .gitignore and in node_modules. A workspace package linked into node_modules, or a built dist folder, is skipped.
cat .gitignore | grep -E "dist|node_modules"
ls -la node_modules/@acme/ui2Fix
Tell Tailwind about the folder with @source in the app's stylesheet. The path is relative to that stylesheet, and should point at source files, not at the built output.
/* apps/web/app/globals.css */
@import "tailwindcss";
@source "../../../packages/ui/src";3Verify
Rebuild and search the CSS output again for the class from the package.
npx next build
grep -rl "your-unique-class" .next/static/cssConfirmed by tailwindcss.com
Cause 2 of 3
Tailwind starts from the wrong base folder
1Check
By default the scanner starts from the current working directory. A root-level command makes that the monorepo root, which can pull in the wrong files or miss the ones you expect.
pwd && cat package.json | grep -A5 '"scripts"'2Fix
Set the base path on the import so scanning is the same wherever the command runs.
@import "tailwindcss" source("../src");
@source "../../../packages/ui/src";3Verify
Run the build from the repo root and from the app folder; both should produce the same classes.
npx next buildConfirmed by tailwindcss.com
Cause 3 of 3
Class names are assembled from strings
1Check
Tailwind reads files as plain text and does not run your code. A name like text-${color}-600 never appears in full, so no CSS is made for it.
grep -rnE "(text|bg|border)-\$\{" packages apps2Fix
Write complete class names in the source, and choose between them.
// wrong
<div className={`text-${error ? 'red' : 'green'}-600`} />
// right
<div className={error ? 'text-red-600' : 'text-green-600'} />3Verify
Rebuild and check that both variants have CSS.
npx next buildConfirmed by tailwindcss.com
How do I stop it coming back?
- Keep one @source line per shared package in the app's stylesheet, committed with the app.
- Point @source at the package's src folder rather than its dist output.
- Use full class names everywhere; add a lint check for template-built classes.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Web apps
Tailwind classes have no effect in a Next.js app
Styles from Tailwind never reach the page after install
The page loads but Tailwind classes do nothing when the generated CSS never reaches the page.
5 causes, each with a fixWeb apps
There is no tailwind.config.js after installing Tailwind 4 and HeroUI in Next.js
HeroUI components render unstyled
Nothing is broken: Tailwind CSS 4 is configured in CSS and no longer creates tailwind.config.js.
3 causes, each with a fixWeb apps
Hydration failed after adding next-themes dark mode
Console reports a server and client mismatch on the html element
next-themes changes the html element and knows the theme only in the browser, so server HTML and client HTML differ.
3 causes, each with a fixWeb apps
Next.js fails with Cannot find module 'tailwindcss'
Error: Cannot find module 'tailwindcss'
Next.js loads Tailwind through PostCSS, so the error means the package named in postcss.config is not installed where the build runs.
3 causes, each with a fixWeb apps
A shadcn/ui Dialog stays open after the form is submitted
Form submits and the data saves, but the modal remains on screen
A shadcn Dialog is a Radix dialog.
3 causes, each with a fixWeb apps
Tailwind CSS 4 build fails on @apply in a Next.js project
Cannot apply unknown utility class
Tailwind 4 only knows its utilities in a stylesheet that imports Tailwind.
2 causes, each with a fix