with-tailwindcss works as expected when installed as instructed in its README. When typescript is installed as instructed in the Next docs, tailwind is rendered inoperative and no styles appear in the browser.
$ npx create-next-app --example with-tailwindcss next-ts-tailwind
$ cd next-ts-tailwind && yarn dev
open http://localhost:3000 >>> App works as expected
Install typescript
$ touch tsconfig.json
$ yarn add --dev typescript @types/react @types/node
$ yarn dev
open http://localhost:3000 >>> App works as expected
Enable typescript
$ mv ./pages/index.js ./pages/index.tsx
$ mv ./pages/_app.js ./pages/_app.tsx
$ mv ./components/nav.js ./components/nav.tsx
$ yarn dev
open http://localhost:3000 >>> App loads without styles
Inspecting page in browser's dev tools shows tailwind classes added to html elements but there is no evidence of tailwind css in the document head.
This condition applies to any single file with a .tsx extension. I need not rename all three .js files to see the failure.
The app should function identically whether files have .js or .tsx extensions.
A worked example is available here.
Following this example from the web, I am able to get Create-React-App + tailwind + typescript to work together, so I see this combination can work.
Moving this /* purgecss end ignore */ to line 8 (below the last tailwind import) seems to fix this. I'm still investigating why that happens though when typescript is enabled vs when its not.
@jamesmosier thank you for looking into this, and pointing me in the right direction!
There appears to be a typescript/purgecss interaction which is the source of the missing styles.
And the answer to that is the postcss.config.js purgecss content: segment only targets '.js' files:
Changing
content: ['./pages/**/*.js', './components/**/*.js'],
to
content: ['./pages/**/*.tsx', './components/**/*.tsx'],
Handles the problem in this case, with index.css left in its original state.
In the with-tailwindcss example the content: ... segment should be changed to something like:
content: [
'./pages/**/*.js', './components/**/*.js',
'./pages/**/*.ts', './components/**/*.ts',
'./pages/**/*.tsx', './components/**/*.tsx'
],
Let me know if you would like a PR opened with this change.
Thanks again for your help!
You're welcome @gihrig, good find with the fix. Feel free to open a PR with the fix, otherwise I can take care of it. Just let me know.
Also instead of listing all the different extensions out, you could do:
content: [
"./pages/**/*.{js,jsx,ts,tsx}",
"./components/**/*.{js,jsx,ts,tsx}"
],
Hi @jamesmosier. I have opened PR #9432 with the fix.
Regarding the updated search path, thanks for that. I spent too much time trying various regex and glob patterns, before resigning myself to a 'workable kludge'. ;-)