'Tailwind UI components aren't renderring correctly in Next.js?
I followed the Tailwind UI getting started documentation, but for some reason it looks nothing like it's supposed to in my Next.js project.
Here is my tailwind.config.ts:
export const defaultTheme = require("tailwindcss/defaultTheme");
module.exports = {
content: ["./src/**/*.{html,js,jsx,ts,tsx}"],
theme: {
extend: {
fontFamily: {
sans: ["Inter var", ...defaultTheme.fontFamily.sans],
},
},
},
plugins: [require("@tailwindcss/forms")],
};
Here's my package.json:
{
"name": "nextjs-app",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@headlessui/react": "^1.5.0",
"@heroicons/react": "^1.0.6",
"next": "12.1.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"tailwindcss": "^3.0.23"
},
"devDependencies": {
"@types/node": "17.0.21",
"@types/react": "17.0.40",
"eslint": "8.11.0",
"eslint-config-next": "12.1.0",
"typescript": "4.6.2"
}
}
Here's my _document.tsx:
import Document, { Html, Head, Main, NextScript } from "next/document";
class MyDocument extends Document {
render() {
return (
<Html>
<Head>
<link
href="https://fonts.googleapis.com/css2?family=Inter&display=optional"
rel="stylesheet"
/>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default MyDocument;
Here is what the Signin component looks like:
Here's what it should look like:
Solution 1:[1]
Add your extra file paths (such as 'components' and 'sections') to tailwind.config.js:
module.exports = {
content: [
"./pages/**/*.{js,ts,jsx,tsx}",
"./components/**/*.{js,ts,jsx,tsx}",
// ADD extra paths here...
],
theme: {
extend: {},
},
plugins: [],
}
As shown here - https://tailwindcss.com/docs/guides/nextjs
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ggootz |


