Skip to content
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

Tailwind CSS base utilities not applied to production builds for TypeScript projects #14595

Closed
dbk91 opened this issue Jun 26, 2020 · 19 comments · Fixed by #14621
Closed

Tailwind CSS base utilities not applied to production builds for TypeScript projects #14595

dbk91 opened this issue Jun 26, 2020 · 19 comments · Fixed by #14621
Labels
good first issue Easy to fix issues, good for newcomers

Comments

@dbk91
Copy link

dbk91 commented Jun 26, 2020

Bug report

Describe the bug

Production builds of Next.js do not apply the base Tailwind utilities in the static build if any components in the pages/ directory imports any external TypeScript components (such as components/nav.tsx), the build only apply the styling added into the

To Reproduce

  1. Create a new NextJS project using yarn create next-app project-name
  2. Select with-tailwindcss example project
  3. Add required TypeScript dependencies yarn add --dev typescript @types/react @types/node
  4. Rename components/nav.js to components/nav.tsx
  5. Run yarn run build && yarn run start
  6. Navigate to http://localhost:3000

Expected behavior

That it would leverage the base Tailwind CSS utilities and appear as the default rather than the screen shot below.

Screenshots

The base utilities, such as flexbox, are lost. Only the styles using the @apply attribute in styles/index.css are applied.
Screenshot_2020-06-26 Screenshot

System information

  • OS: macOS
  • Version of Next.js: 9.2.0
  • Version of Node.js: 14.4.0

Additional context

This doesn't seem to happen if any page components are using TypeScript, only if the components that the page components import are using TypeScript.

@timneutkens
Copy link
Member

Think this is a tailwind bug actually, where it uses PurgeCSS only on .js files 🤔 cc @adamwathan

@timneutkens timneutkens added the Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.). label Jun 26, 2020
@adamwathan
Copy link
Contributor

Hey! Make sure you are configuring Tailwind to look through all the relevant files here:

https://github.com/vercel/next.js/blob/canary/examples/with-tailwindcss/tailwind.config.js#L2

The example you started with is only looking for .js files, so you just need to update that array of paths to also make sure it's looking for any other file types that might contain any markup.

@dbk91
Copy link
Author

dbk91 commented Jun 26, 2020

Ah, that did it. Feel a little silly for missing that. Thanks for the quick response!

@timneutkens
Copy link
Member

We'll want to update that example to also include .tsx .jsx and .ts

@timneutkens timneutkens added good first issue Easy to fix issues, good for newcomers and removed Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.). labels Jun 27, 2020
@kodiakhq kodiakhq bot closed this as completed in #14621 Jun 27, 2020
kodiakhq bot pushed a commit that referenced this issue Jun 27, 2020
rokinsky pushed a commit to rokinsky/next.js that referenced this issue Jul 11, 2020
@wouterds
Copy link

wouterds commented Dec 30, 2020

Don't know how I got it wrong (as I was using it pre TailwindcssV2 and everything was fine). But changing purge in tailwind.config.js as in the one @adamwathan mentioned resolved my issues.

@Mayank-Dev-23
Copy link

i am having a same issue i created a next js website with tailwind css but when i deploy only the base style apply and all other styles not apply i name my components as .js how to fir this bug help

@rsipakov
Copy link
Contributor

rsipakov commented Jun 10, 2021

i am having a same issue i created a next js website with tailwind css but when i deploy only the base style apply and all other styles not apply i name my components as .js how to fir this bug help

For me work this code in tailwind.css:
@tailwind base;
/* purgecss start ignore */
@tailwind components;
@tailwind utilities;
/* purgecss end ignore */

example https://github.com/missioniz/greenera/blob/master/src/styles/globalStyles/tailwindcss.css

@JosiasAurel
Copy link

I am currently experiencing a similar issue. Here is my tailwind config

module.exports = {
  purge: ["./pages/**/*.{js, ts, jsx, tsx}", "./components/**/*.{js,ts,jsx,tsx}"],
  darkMode: false, // or 'media' or 'class'
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
}

I only have a pages and components folder like that in the config.

@henke443
Copy link

henke443 commented Jul 3, 2021

I am currently experiencing a similar issue. Here is my tailwind config

module.exports = {
  purge: ["./pages/**/*.{js, ts, jsx, tsx}", "./components/**/*.{js,ts,jsx,tsx}"],
  darkMode: false, // or 'media' or 'class'
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
}

I only have a pages and components folder like that in the config.

I had this exact same issue and it will work when you change "./pages/**/*.{js, ts, jsx, tsx}" to "./pages/**/*.{js,ts,jsx,tsx}".

@mahijendra
Copy link

mahijendra commented Jul 7, 2021

I've been trying to solve this complication for the past 2 hours. I've tried every method mentioned here. Still not working :( @adamwathan
Screenshot 2021-07-07 at 9 18 12 PM

@lucasoz
Copy link

lucasoz commented Jul 11, 2021

I've been trying to solve this complication for the past 2 hours. I've tried every method mentioned here. Still not working :( @adamwathan
Screenshot 2021-07-07 at 9 18 12 PM

Same for me

@estruyf
Copy link

estruyf commented Jul 12, 2021

Experiencing this as well, and just found out that clearing the build cache or doing a package.json update fixes it until new classes get introduced.

@AR-Student824
Copy link

None of the solutions mentioned here are working

@adamwathan
Copy link
Contributor

Can you folks please open issues on Tailwind itself if you're having problems and include a reproduction? I can't get this to happen in a fresh project, so if someone can provide a reproduction I'll have a much easier time figuring out the issue.

@estruyf
Copy link

estruyf commented Jul 19, 2021

@adamwathan I wasn't aware of the new JIT compiler. I will test this one out and see if the issue still occurs, but on my end, it only seems to happen during production builds on Vercel. Not on my local machine(s).

@Nick-Achee
Copy link

Hi there everyone! I don't have a solution for this but I am experiencing the same issue. I will keep searching StackOverflow and let you know if I find something. Chat soon 🤙

@adamwathan
Copy link
Contributor

@Nick-Achee Please open an issue here with a reproduction and we can fix it:

https://github.com/tailwindlabs/tailwindcss

Right now I have absolutely no information to go off of. I can't help unless someone gives me an example project, our own Next.js projects (we have many of them) don't suffer from this at all.

@Nick-Achee
Copy link

@adamwathan - I went ahead and added the other file types to all purge paths and it fixed the issue.

Working in production now. Thanks.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.