close
The Wayback Machine - https://web.archive.org/web/20220528123117/https://github.com/tailwindlabs/tailwindcss/discussions/2833
Skip to content

Tailwind not working in create-react-app #2833

Answered by adamwathan
erpriliano asked this question in Help
Tailwind not working in create-react-app #2833
Nov 20, 2020 · 16 answers · 23 replies

Hi there,

Basically I've already followed the steps to include tailwindcss into my react-app, these are the steps I followed :

  1. Create react-app from npx using npx create-react-app [project-name] and I open it
  2. Then I installed tailwindcss using this command npm install tailwindcss autoprefixer postcss-cli
  3. I created config file and postcss.config.js using these commands npx tailwindcss init and touch postcss.config.js. I'm doing both in my root project folder
  4. Inside my src folder, I created folder called styles with two files (tailwind.css & main.css)
  5. Then I edited my script inside my package.json

My postcss.config.js

const tailwindcss = require("tailwindcss");
module.exports = {
    plugins: [
        tailwindcss("./tailwind.config.js"),
        require("autoprefixer")
    ]
};

Inside postcss.config.js I keep getting a warning says:

Could not find a declaration file for module 'tailwindcss'. '/Users/erpriliano/React/kajol-web/node_modules/tailwindcss/lib/index.js' implicitly has an 'any' type.
Try npm install @types/tailwindcss if it exists or add a new declaration (.d.ts) file containing declare module 'tailwindcss';

My tailwind.css

@tailwind base;
@tailwind components;
@tailwind utilities;

My package.json

{
  "name": "kajol-web",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "autoprefixer": "^9.0.0",
    "postcss-cli": "^7.1.2",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-scripts": "4.0.0",
    "tailwindcss": "^2.0.1",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "start": "npm run watch:css && react-scripts start",
    "build": "npm run build:css && react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "build:css": "postcss src/styles/tailwind.css -o src/styles/main.css",
    "watch:css": "postcss src/styles/tailwind.css -o src/styles/main.css"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Then I ran npm start but always got these errors:

kajol-web@0.1.0 start /Users/erpriliano/React/kajol-web
npm run watch:css && react-scripts start

kajol-web@0.1.0 watch:css /Users/erpriliano/React/kajol-web
postcss src/styles/tailwind.css -o src/styles/main.css

Error: PostCSS plugin postcss-nested requires PostCSS 8.
Migration guide for end-users:
https://github.com/postcss/postcss/wiki/PostCSS-8-for-end-users
at Processor.normalize (/Users/erpriliano/React/kajol-web/node_modules/postcss/lib/processor.js:167:15)
at new Processor (/Users/erpriliano/React/kajol-web/node_modules/postcss/lib/processor.js:56:25)
at postcss (/Users/erpriliano/React/kajol-web/node_modules/postcss/lib/postcss.js:55:10)
at /Users/erpriliano/React/kajol-web/node_modules/tailwindcss/lib/util/parseObjectStyles.js:24:33
at arrayMap (/Users/erpriliano/React/kajol-web/node_modules/lodash/lodash.js:639:23)
at map (/Users/erpriliano/React/kajol-web/node_modules/lodash/lodash.js:9580:14)
at Function.flatMap (/Users/erpriliano/React/kajol-web/node_modules/lodash/lodash.js:9283:26)
at parseObjectStyles (/Users/erpriliano/React/kajol-web/node_modules/tailwindcss/lib/util/parseObjectStyles.js:23:26)
at parseObjectStyles (/Users/erpriliano/React/kajol-web/node_modules/tailwindcss/lib/util/parseObjectStyles.js:20:12)
at /Users/erpriliano/React/kajol-web/node_modules/tailwindcss/lib/util/processPlugins.js:37:123
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! kajol-web@0.1.0 watch:css: postcss src/styles/tailwind.css -o src/styles/main.css
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the kajol-web@0.1.0 watch:css script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/erpriliano/.npm/_logs/2020-11-20T00_38_53_408Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! kajol-web@0.1.0 start: npm run watch:css && react-scripts start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the kajol-web@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/erpriliano/.npm/_logs/2020-11-20T00_38_53_429Z-debug.log

I googled and I found the same problem in stackoverflow as this and it already two months ago but there's no satisfying answer of how to fix it. Could you please help us with this problem?

Running npm install postcss@latest should fix it 👍🏻

Replies

16 suggested answers
·
23 replies

Running npm install postcss@latest should fix it 👍🏻

5 replies
@erpriliano

Yes, problem solved and I'm realised by now that I haven't installed postcss at all in that package.json. Thanks :)

@dwbelliston

@erpriliano - in the tailwind docs its mentioned using CRACO to get it working, but here you are not, can you help me learn why this way instead of via CRACO?

@erpriliano

To be honest with you, the moment I asked the question the docs for installing tailwind in CRA haven't published yet so I've to add it manually by using previous docs and need to did some improvement a bit as needed in my project.

Answer selected by erpriliano

I've managed to get it to work by following the guide for PostCSS 7 compatibility build here. I just changed it to yarn add tailwindcss@npm:@tailwindcss/postcss7-compat postcss-cli@^7 autoprefixer@^9 since I'm using yarn and postcss-cli.

1 reply
@felipe-campanhol

Thanks!, installing this way solved my issue

I have tried every possible way to install tailwindcss in my createReactApp project but never worked, please I need some help

1 reply
@erpriliano

Now that tailwind has provided us with some comprehensive explanation of how to install it in our CRA project. You might want to see this

1 reply
@erpriliano

Can you tell us what's the error? And also explain to us of how you install tailwind to your project step by step

0 replies

@Asaju5 What version of Node are you using? Tailwind requires a minimum of v12 in case you are on an earlier version.

1 reply
@JoseAlz

work! ajaja Setting up Tailwind CSS
Tailwind CSS requires Node.js 12.13.0 or higher.

4 replies
@erpriliano

I'm trying to guess that your problem is with your Node, will you try to re-install node on your PC? See if that works..

@smrnjeet222

@Asaju5 I'm also facing the exact same issue

@sagor9116

The new documentation is working fine. https://tailwindcss.com/docs/guides/create-react-app . go to the link and try to the installation part step by step. I hope it will work

Hello, I'm having problems starting my React project with TailwindCss with both NPM and YARN represent the same error, and I'm definitely not sure what to do to solve this problem. (Obs: I'm not fluent in the English language, I'm Brazilian, I'm sorry for any mistakes in transcription.

yarn start
yarn run v1.22.5
$ craco start
(node:31360) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_VALUE]: The argument 'id' must be a non-empty string. Received ''
at Module.require (internal/modules/cjs/loader.js:1020:11)
at require (internal/modules/cjs/helpers.js:72:18)
at getConfigAsObject (C:_xampp_7.4\htdocs_services\2k21\tchaau.com.br\frontend\node_modules@craco\craco\lib\config.js:46:20)
at loadCracoConfigAsync (C:_xampp_7.4\htdocs_services\2k21\tchaau.com.br\frontend\node_modules@craco\craco\lib\config.js:69:34)
at Object. (C:_xampp_7.4\htdocs_services\2k21\tchaau.com.br\frontend\node_modules@craco\craco\scripts\start.js:22:1)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
(node:31360) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:31360) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.)

3 replies
@wilcus

Probably you do not put the configuration files in the root folder

@TutorialDoctor

Probably you do not put the configuration files in the root folder

This was my issue.

honestly, the install process is insanely complicated, and there are numerous conflicting guides on the internet.

This is so horrible... smh

1 reply

I would suggest using Vite instead of Create React App.

Creating a Vite app

  • It is the fastest (give it a try and you'll realize)
  • Tailwind installation is damn easy
0 replies

I followed every step here and it works in development. But when I deploy to Heroku, the error log says:

Error: Cannot find module tailwindcss 🤷🏽‍♂️

1 reply
@davidofug

For me on Development it gives me the error.

I have the same error. Works perfectly in development but in Heroku I am getting Error: cannot find module 'tailwindcss' and the build doesn't complete

0 replies

Hi everyone!
Please I have a problem with tailwindcss using react.
My styling is not working on production stage but on development everything works fine.
What could be the problem??

this is my package.json
{ "name": "cra-pwa", "version": "0.1.0", "private": true, "homepage": "https://sammiearchie77.github.io/my-portfolio", "dependencies": { "@craco/craco": "^6.2.0", "@heroicons/react": "^1.0.3", "@testing-library/jest-dom": "^5.14.1", "@testing-library/react": "^11.2.7", "@testing-library/user-event": "^12.8.3", "axios": "^0.21.1", "gh-pages": "^3.2.3", "react": "^17.0.2", "react-dom": "^17.0.2", "react-scripts": "4.0.3", "web-vitals": "^0.2.4", "workbox-background-sync": "^5.1.4", "workbox-broadcast-update": "^5.1.4", "workbox-cacheable-response": "^5.1.4", "workbox-core": "^5.1.4", "workbox-expiration": "^5.1.4", "workbox-google-analytics": "^5.1.4", "workbox-navigation-preload": "^5.1.4", "workbox-precaching": "^5.1.4", "workbox-range-requests": "^5.1.4", "workbox-routing": "^5.1.4", "workbox-strategies": "^5.1.4", "workbox-streams": "^5.1.4" }, "scripts": { "start": "craco start", "predeploy": "npm run build", "deploy": "gh-pages -d build", "build": "craco build", "test": "craco test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] }, "devDependencies": { "autoprefixer": "^9.8.6", "postcss": "^7.0.36", "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.2.7" } }

this is my tailwind.config.js
module.exports = { purge: ['./src/**/*.{js,jsx,ts,tsx', './public/index.html'], darkMode: false, // or 'media' or 'class' theme: { extend: {}, }, variants: { extend: {}, }, plugins: [], }

0 replies
2 replies
@rahulrg1

if you have done whatever is stated here " https://tailwindcss.com/docs/guides/create-react-app "
after this if everything is working fine except your tailwind css then try one way to fix (if you haven't tried it yet)

  1. go to your main folder path in terminal where you have installed your node js earlier.
  2. then type " npm uninstall -g create-react-app "
  3. after that " npm install -g create-react-app"
  4. then follow this again https://tailwindcss.com/docs/guides/create-react-app
    this might help you, actually u may have the " npm create-react-app " older version then this steps will work.
@jaikangam

Someone still looking for a solution, what @rahulrg1 said is true. Uninstall and get the latest version of create-react-app.

Can anyone help me? my client want to go react-scripts@4.0.3 but after going the tailwindcss not not working

3 replies
@seungjoonrim

BUMP - i am having the same problem

@glasscloud

I ran into the same problem today. Needed to downgrade react-scripts from 5.0.1 to 4.0.3 and after doing that tailwind styling no longer worked.

@melhassouni

i had the same issue just today i had to downgrade my react-scripts from 5.0.1 to 4.0.3 but tailwind stopped working. does anyone knows any solution ?

npm install -D tailwindcss postcss@latest autoprefixer this works. But recommended to uninstall the create-react-app and get the latest version.

I got the same issue. Seem it is because of dependency.

If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app or yarn global remove create-react-app to ensure that npx always uses the latest version.

This is from the Create-react-app doc.

0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet