3

I am trying to add tailwind css with react app. I followed the tailwind documentation,how to set up tailwind with react.

I tried with tailwind latest version.I checked Nodejs and npm are installed perfectly.

But when i run the npm run start it always get an error. I can't fix the problem.

enter image description here

package.json

{
  "name": "tailwind-css",
  "version": "0.1.0",
  "homepage": "",
  "private": true,
  "dependencies": {
    "@craco/craco": "^6.1.2",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router-dom": "^5.2.0",
    "react-scripts": "^4.0.3"
  },
  "scripts": {
    "start": "craco start",
    "build": "craco build",
    "test": "craco test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "engines": {
    "npm": "6.14.6",
    "node": "12.18.4"
  },
  "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.2"
  }
}

Please anyone help.

6
  • Have you tried reinstalling node_modules yet? Commented Jun 21, 2021 at 7:43
  • 1
    this is not tailwind error Commented Jun 21, 2021 at 8:01
  • Sorry everyone, This error was in react scripts modules.Now working fine.Thanks all. Commented Jun 21, 2021 at 8:42
  • @MijanurRahman Can you pls clarify how exactly you fixed this? Commented Jun 18, 2022 at 18:15
  • 2
    @GeniusHawlah You need react-scripts v5.0.0 or greater for tailwind to work. Commented Oct 17, 2022 at 22:52

4 Answers 4

9

If you follow tailwind documents way, then try this, in the package.json

  "scripts": {
    "start": "craco start && postcss src/css/app.css -o public/app.css", <--- need to inser postcss script as your css reference path.
    "build": "craco build",

and also check your craco.config.js like this.

module.exports = {
  style: {
    postcss: {
      plugins: [require("tailwindcss"), require("autoprefixer")],
    },
  },
};

happy coding!

Sign up to request clarification or add additional context in comments.

Comments

5

Just update your react-script from v4 to lastest 5 version by: npm install react-scripts@latest. If you will stay with version 4 you have to use craco

That was helpful for me

2 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
This fixed it for me. I updated my node and did a force update for npm vulnerabilities. Thank you!
2

Just use CDN in Publuc>index.html

<script src="https://cdn.tailwindcss.com"></script>

Comments

1

Try to Write this in tailwind.config.js :

module.exports = 

    {
      content: [
        "./index.html",
        "./src/**/*.{js,ts,jsx,tsx}"
      ].
    ..///
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.