-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
TailwindCSS not working in NX NextJS project. #8355
Comments
I'm having the exact same issue following the Egghead course. Using tailwindcss Nx report:
|
So, I just got it working. In
|
@mathias-lundin, I could have sworn I tried that, but I did just as you have above and... it worked! Thanks for posting the solution here. |
Take a look at Juri's article series -- he has slightly different Tailwind configuration. |
I'm having issues getting the components that are library generated to render the styles with the rest of the application. I've been following this article and with help from the comments above I got my main application to render styles. Here's the kicker, the library styles only work if they are first added as a class to an element in the app. Any Idea how to fix this? Ref
const {join, dirname} = require('path');
// Following this guide
// https://blog.nrwl.io/setup-next-js-to-use-tailwind-with-nx-849b7e21d8d0
module.exports = {
plugins: {
tailwindcss: {
config: join(__dirname, 'tailwind.config.js'),
},
autoprefixer: {},
},
};
const { join } = require('path');
const { createGlobPatternsForDependencies } = require('@nrwl/next/tailwind');
// apps/site/tailwind.config.js
module.exports = {
presets: [require('../../tailwind-workspace-preset.js')],
mode: 'jit',
content: [
join(__dirname, '**/*.{js,ts,jsx,tsx}'),
...createGlobPatternsForDependencies(__dirname),
],
theme: {
extend: {},
},
plugins: [],
};
module.exports = {
// since we already have our own resets for both app and view, we don't use the tailwind preflight reset
corePlugins: {
preflight: false,
},
// we also enable !important, because we often need to override materials base css, and without it, we will have to add ! to every statement anyways
important: true,
theme: {
extend: {},
},
variants: {
extend: {},
},
}
{
"compileOnSave": false,
"compilerOptions": {
"rootDir": ".",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2015",
"module": "esnext",
"lib": ["es2017", "dom"],
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"baseUrl": ".",
"paths": {
"@evolvingsoftware/tailwind-ui": ["./libs/tailwind-ui/src/index.ts"]
}
},
"exclude": ["node_modules", "tmp"]
}
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx",
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
} |
@juristr Could you take a look at this? |
I just had the same issue. The function |
Hello. I posted a working (for me) example here: #8072 (comment) |
Fresh install of NextJS + TailwindCSS and I am getting the same issue |
I got it working with the following config (react app not nextjs but I think it should work)
module.exports = {
plugins: {
tailwindcss: { config: './tailwind.config.js' },
autoprefixer: {},
},
};
module.exports = {
mode: 'jit',
content: ['./src/**/*.{js,ts,jsx,tsx,html,css}'],
theme: {
extend: {},
},
plugins: [],
}; |
I am not completely sure that I understood the problem you're facing fully, however I might have encountered the similar issue that I'll try to explain briefly, as well as the approach that solved the issue for me. So, to put into perspective and give a little context, I had the following setup in my NX workspace:
As if you were to image, my application is just importing Now that we got that out of the way (disclaimer: it is not of a great importance to completely understand the architecture of the application, but rather that I had the library approach for different UI elements) let me clarify the issue that I have encountered and how I managed to solve it. Once the application is started I see that no TailwindCSS styles are applied to my application elements. If you were to remember as explained previously, I had no UI elements defined in the application itself, but rather there were coming from my feature modules (NX Angular libraries). On the other hand, if I was to define an element in my How I managed to fix it, is basically create the right glob pattern, as you already explained. However, I needed to change a configuration just a little, to point Tailwind to the right path. The configuration in my
And for some reason was not able to pickup any styles defined in the UI components. In other words, no styles got applied to any of the UI elements defined in my feature libraries (as they were not referenced / used from within the application template). After a few tweaks, I was able to fix this issue by constructing the right path to source files using the following fix in my
After this change, all the styles were applied properly to all the UI elements, no matter if they were defined in the feature libraries or directly in my Note: I am currently having a single (Angular) application, but am still using project based I hope this might be useful to others that encountered the same / similar issue like me, of not having styles properly applied to elements / pages defined in the libraries (that were not referenced directly in the application component templates) and being properly defined in the elements / classes used from within the application that has TailwindCSS configured using Disclaimer: I do not think that this is framework specific approach, although I might be wrong, and should work as long as the styles are not properly applied to library defined UI elements that are not used from within the application templates. |
I also encountered this error with my Next.js project (unrelated to the Egghead course mentioned by others). module.exports = {
content: ['./src/pages/**/*.{js,jsx,ts,tsx}', './src/components/**/*.{js,jsx,ts,tsx}'],
theme: {
extend: {},
},
plugins: [],
} |
Hi! I'm also having problems getting tailwind 3 to work with nx + next.js. I've tried the various approaches suggested in this issue but have not had any success :-( Posted a discussion with more details on my set up on the tailwind repo here Let me know if anyone has ideas! |
const { join } = require('path');
module.exports = {
content: [
join(__dirname, "pages/**/*.{js,ts,jsx,tsx}"),
join(__dirname, "components/**/*.{js,ts,jsx,tsx)"),
],
theme: {
extend: {},
},
plugins: [
require('@tailwindcss/forms'),
],
} This fixed the problem for me |
It isn't working for me. I used a fresh install of with-tailwind in examples directory... |
I have the same problem, someone found the solution? |
just use this in styles/globals.css
|
Hello, I am facing the same issue. Have you found a solution for this? |
Hello Community, I faced the same issue and found a solution. Some background: let's keep in mind that we have to different The solution was to include the path to my component's library in the
You will end up with a module.exports = {
content: [
"./packages/comodin-web-app/pages/**/*.{js,ts,jsx,tsx}",
"./packages/comodin-web-app/components/**/*.{js,ts,jsx,tsx}",
"./packages/shared/ui/src/lib/**/*.{js,ts,jsx,tsx}", //this was missing
],
theme: {
extend: {},
},
plugins: [],
} and a module.exports = {
content: [
"./packages/shared/ui/src/lib/**/*.{js,ts,jsx,tsx}", //this path must also be include in the web app configuration
],
theme: {
extend: {},
},
plugins: [],
} I hope this helps. Note: this configuration does not consider css purging. I will update my answer once I have that feature configured. Note 2: there is a concept of tailwind presets see here and here that may result in a more elegant approach to import the content for your component library styles. |
I also encounter same things, just exactly copying from my last project but not working either, |
The guide here is up to date to provide correct config, with purging as well. https://nx.dev/guides/using-tailwind-css-in-react The main thing is the utility we provide for including dependencies in // apps/app1/tailwind.config.js
const { createGlobPatternsForDependencies } = require('@nrwl/react/tailwind');
const { join } = require('path');
module.exports = {
content: [
join(
__dirname,
'{src,pages,components}/**/*!(*.stories|*.spec).{ts,tsx,html}'
),
...createGlobPatternsForDependencies(__dirname),
],
theme: {
extend: {},
},
plugins: [],
}; If you are having more issues after following the guide, please re-open a new issue with more details on what is wrong. |
You can also check out our usage of Tailwind in our nx.dev app. https://github.com/nrwl/nx/blob/master/nx-dev/nx-dev/tailwind.config.js |
if paths are correct, simply try this: module.exports = { In my case, after hours of debugging, I found that tailwind css was compiled on all of the components and pages but the other 3rd party library (in my case MUI ) was overriding the styles, so I set! important for the tailwind code. |
- https://egghead.io/lessons/tailwind-setup-next-js-with-tailwind-in-a-nx-workspace - yarn add tailwindcss postcss autoprefixer -D - cd apps/site && npx tailwindcss init -p - nrwl/nx#8355 (comment)
We had a similar problem - one of our ui packages was not being picked up by Tailwind's JIT and did not generate any classes. After some debugging we found out that |
Guys, mb it will help someone. I had same problem and it was because I forgot to put |
I switched from |
For me, I misspelled the file name |
This solution worked for me. |
I had the same issue, stumbled upon this (https://nx.dev/recipes/other/using-tailwind-css-in-react) official guide which worked for me |
This solution worked for me also - appreciate it! |
I am using next.js (2-28-2023) and have this issue, could not git the grid to work - until I only change the
Thank you for sharing!!!!!! |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
Following the egghead tutorial for a NextJS project with a new nx-workspace, installing Tailwind is not working. Tailwind styles are not applied to the page.
Follow steps in this guide: https://egghead.io/lessons/tailwind-setup-next-js-with-tailwind-in-a-nx-workspace or in the steps to reproduce below.
Expected Behavior
Tailwind styles are applied to the page.
Steps to Reproduce
npx create-nx-workspace zip-finder --packageManager=yarn
What to create in the new workspace?
next
Application name?
app
Default stylesheet format
css
Use Nx cloud
no
cd zip-finder
(workspace name)yarn add -D tailwindcss@latest postcss@latest autoprefixer@latest
cd apps/app
npx tailwindcss init -p
Replace
pages/styles.css
withReplace
postcss.config.js
with:Replace
pages/index.tsx
with something simple like:You should see the
test
class applying the color red to the text, but no Tailwind classes are applied. If you searchtailwind
in the Dev Tools Elements panel, you'll see Tailwind is loaded in the DOM.Adding this to
tailwind.config.js
doesn't help either:Best way to repro is from @juristr 's egghead tutorial (which is the same as the steps listed above).
Failure Logs
Environment
Nx Report:
Tailwind
3.x.x
is used, but I couldn't find any different install instructions vs. the2.x.x
version used in the egghead tutorial.Thanks for having a look!
The text was updated successfully, but these errors were encountered: