Tailwind JIT doesn't work with Next.js
See original GitHub issueCurrent Behavior
When Tailwind JIT mode is enabled, applying Tailwind rules within css files only works:
h1 {
@apply bg-[#fef]
}
However, it is impossible to use Tailwind rules within tsx
files at all:
export function Index() {
return <>
<h1 className='bg-[#fef]'>Rules hasn't been applied!</h1>
<h1 className='font-bold'>Rules hasn't been applied!</h1>
</>;
}
export default Index;
P.S. I generated a Next.js application without NX and it works. Seems like it’s a bug in the executor.
Expected Behavior
Tailwind rules have to be applied with the JIT mode enabled.
Steps to Reproduce
npx --ignore-existing create-nx-workspace happynrwl --preset=next
cd happynrwl
npm install -D tailwindcss@latest postcss@latest autoprefixer@latest
cd apps/frontend
npx tailwindcss init -p
- Edit
postcss.config.js
:
module.exports = {
plugins: {
tailwindcss: { config: './apps/frontend/tailwind.config.js' },
autoprefixer: {},
},
};
- Edit
tailwindcss.config.js
:
const { createGlobPatternsForDependencies } = require('@nrwl/react/tailwind');
module.exports = {
mode: 'jit'
purge: createGlobPatternsForDependencies(__dirname),
// ...
};
- Add the following lines to
styles.css
:
@tailwind base;
@tailwind components;
@tailwind utilities;
h1 {
@apply bg-[#0ff]
}
- Add some tags to
index.tsx
:
export function Index() {
return <>
<h1>Red title works!</h1>
<h2 className='bg-green-400'>Green title doesn't work!</h2>
</>;
}
10. `npm run start`
Environment
Node : 14.17.3
OS : linux x64
npm : 6.14.13
nx : Not Found
@nrwl/angular : Not Found
@nrwl/cli : 12.5.7
@nrwl/cypress : 12.5.7
@nrwl/devkit : 12.5.7
@nrwl/eslint-plugin-nx : 12.5.7
@nrwl/express : Not Found
@nrwl/jest : 12.5.7
@nrwl/linter : 12.5.7
@nrwl/nest : Not Found
@nrwl/next : 12.5.7
@nrwl/node : Not Found
@nrwl/react : 12.5.7
@nrwl/schematics : Not Found
@nrwl/tao : 12.5.7
@nrwl/web : 12.5.7
@nrwl/workspace : 12.5.7
@nrwl/storybook : 12.5.7
@nrwl/gatsby : Not Found
typescript : 4.2.4
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:18 (7 by maintainers)
Top Results From Across the Web
next.js - JIT mode for Tailwind not working in localhost preview ...
JIT mode is not working on Localhost but Production is good. I have opened the discussion on Tailwind Repo (I thought it was...
Read more >How to setup Tailwind CSS JIT with NextJS - Dev Sharma
TailwindCSS JIT mode brings in a ton of improvements. In this tutorial, we will learn how to set TailwindCSS JIT with NextJS.
Read more >TailwindCSS not working in NX NextJS project. #8355 - GitHub
Current Behavior Following the egghead tutorial for a NextJS project with a new nx-workspace, installing Tailwind is not working.
Read more >Tailwind JIT with Next.js - William Kurniawan
Tailwind CSS is a utility-first CSS framework which allows developers to rapidly build modern websites.
Read more >Tailwind Just in Time Tutorial #5 - Tailwind JIT with Next.js
Hey gang, in this tutorial you'll learn how to use Tailwind Just in Time with a Next. js application. ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks folks. Let me have a look at this and see how/whether we can improve the experience here. Won’t be able this week though. Next week’s blog post for the Next + Nx + Tailwind series will be about Storybook and Tailwind. Might be next or the week after. I have to first do some adjustments in the Nx src.
I’ll try to look into this as part of that work. Will ping you for further clarifications 🙂
@marckassay yep, ofc 😅