'tailwindcss' 未被识别为内部或外部命令

我已经为我的 react 库预先安装了 tailwind css 并添加了一个名为 build-css 的脚本,但运行它,npm run build-css 它给了我以下错误:'tailwindcss' 不被识别为内部或外部命令

package.json 文件

{
  "name": "react-firebase-authentication",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.9",
    "@testing-library/react": "^11.2.3",
    "@testing-library/user-event": "^12.6.0",
    "autoprefixer": "^9.8.8",
    "postcss": "^7.0.39",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-icons": "^4.3.1",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.1",
    "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.2.17",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "build-css": "tailwindcss build src/styles.css -o public/styles.css",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts 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"
    ]
  }
}

CMD 错误 CMD ss

stack overflow 'tailwindcss' is not recognized as an internal or external command
原文答案
author avatar

接受的答案

安装 postcss-cli 将有助于解决问题。

npm install -D postcss postcss-cli

答案:

作者头像

如果您使用的是 Tailwind 2.x,则必须使用 Craco 来正确配置它。请遵循 Tailwind 文档中的 this guideline