Description
I have a Turborepo monorepo set up with the following structure:
root/
├── apps/
│ ├── web/ # Next.js app
│ │ ├── src/
│ │ ├── package.json
│ │ ├── tailwind.config.js # Imports shared config
│ │ └── postcss.config.mjs # Imports shared config
│ ├── docs/ # (optional docs app)
│
├── packages/
│ ├── ui/ # UI component library
│ │ ├── src/
│ │ │ └── styles.css
│ │ ├── dist/
│ │ │ ├── index.js
│ │ │ └── styles.css
│ │ ├── package.json
│ │
│ ├── tailwind-config/ # Shared Tailwind config package
│ │ ├── tailwind.config.js
│ │ ├── postcss.config.mjs
│ │ └── package.json
│
└── package.json (root)
Root package.json
{
"private": true,
"workspaces": ["apps/*", "packages/*"],
"devDependencies": {
"tailwindcss": "^4.1.12",
"@tailwindcss/postcss": "^4.1.12",
"postcss": "^8.5.6",
"turbo": "^2.5.4"
}
}
Shared Tailwind Config (packages/tailwind-config/tailwind.config.js)
import path from "path";
export default {
content: [
path.join(__dirname, "../../apps/**/*.{js,ts,jsx,tsx}"),
path.join(__dirname, "../../packages/**/*.{js,ts,jsx,tsx}")
],
theme: {
extend: {},
},
plugins: [],
};
Shared PostCSS Config (packages/tailwind-config/postcss.config.mjs)
export default {
plugins: {
"@tailwindcss/postcss": {},
},
};
UI Package (packages/ui/package.json)
{
"name": "@astra/ui",
"version": "1.0.0",
"main": "./dist/index.js",
"sideEffects": ["**/*.css"],
"files": ["dist"],
"scripts": {
"build:css": "tailwindcss -i ./src/styles.css -o ./dist/styles.css",
"dev:css": "tailwindcss -i ./src/styles.css -o ./dist/styles.css --watch",
"build": "npm run build:css && tsc"
}
}
Web App Tailwind Config (apps/web/tailwind.config.js)
import config from "@repo/tailwind-config/tailwind.config.js";
export default config;
Web App PostCSS Config (apps/web/postcss.config.mjs)
import config from "@repo/tailwind-config/postcss.config.mjs";
export default config;
Web App Global CSS (apps/web/app/global.css)
@import "@astra/ui/dist/styles.css";
The Problem
The UI components from @astra/ui render, but none of the Tailwind CSS styles are applied.
Even default Tailwind utility classes in apps/web are not working (e.g., bg-red-500 does nothing).
Breakpoints (sm:, md:, etc.) also do not apply.
The Tailwind CLI build in @astra/ui does generate dist/styles.css, but when imported in the web app, styles are still missing.
PostCSS and Tailwind config are both imported from the shared @repo/tailwind-config package.
What I Tried
Deleting node_modules, .turbo, and dist folders and reinstalling dependencies.
Running tailwindcss -i ./src/styles.css -o ./dist/styles.css inside packages/ui.
Verifying that content paths in the shared tailwind.config.js include both apps and packages.
Making sure "sideEffects": ["**/*.css"] is set in
packages/ui/package.json so CSS isn’t tree-shaken.Importing the built CSS in apps/web/app/global.css.
Question
Why aren’t Tailwind styles applying in my Next.js app when using:
A Turborepo monorepo
A shared Tailwind config package
A separate UI component library that outputs built CSS?
What is the correct way to configure Tailwind so styles are applied
across both the web app and the UI package in this setup?