来自 CSS React 构建中的 Minimizer 插件的未知单词错误

Unknown word error from CSS Minimizer plugin on React build

由于 CSS Minimizer 插件的“未知词”错误,React 构建失败。当我 运行 npm run build, 它不断失败!

Failed to compile.

static/css/main.d3e3749c.css from Css Minimizer plugin static\css\main.d3e3749c.css:698:13: Unknown word [:1,0][static/css/main.d3e3749c.css:698,13]

我的Node版本是v16.14.0。在 npm start, 中一切正常,但构建失败。也许这是由于 PostCSS。我尝试降级相同的版本,但没有用。

package.json

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.8.1",
    "@emotion/styled": "^11.8.1",
    "@mui/icons-material": "^5.4.4",
    "@mui/material": "^5.4.4",
    "@testing-library/jest-dom": "^5.16.1",
    "@testing-library/react": "^12.1.2",
    "@testing-library/user-event": "^13.5.0",
    "axios": "^0.26.0",
    "emoji-mart": "^3.0.1",
    "moment": "^2.29.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-helmet-async": "^1.2.3",
    "react-infinite-scroll-component": "^6.1.0",
    "react-redux": "^7.2.6",
    "react-router-dom": "^6.2.1",
    "react-scripts": "5.0.0",
    "react-scroll-to-bottom": "^4.2.0",
    "react-slick": "^0.28.1",
    "react-toastify": "^8.2.0",
    "redux": "^4.1.2",
    "redux-devtools-extension": "^2.13.9",
    "redux-thunk": "^2.4.1",
    "slick-carousel": "^1.8.1",
    "socket.io-client": "^4.4.1",
    "web-vitals": "^2.1.3",
    "webfontloader": "^1.6.28"
  },
  "scripts": {
    "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"
    ]
  },
  "devDependencies": {
    "autoprefixer": "^10.4.2",
    "postcss": "^8.4.8",
    "tailwindcss": "^3.0.23"
  }
}

我遇到了同样的问题,在我的情况下,错误是由 tailwind JIT 模式引起的。 我有这样的风格:

top-[${positionFromTop}]

在我的一个文件中,这导致了错误。

要查找错误原因,您应该使用 tailwind CLI 运行 npx tailwindcss -i ./src/{YOUR_MAIN_CSS_FILE}.css -o ./dist/output.css --watch 命令,然后检查 output.css 是否有任何语法错误。然后就是修复导致语法错误的样式。

我正在从 tailwindcss 中的状态传递数据 class。

top-[${positionFromTop}]

解决方案:不要使用任何花哨的东西CSS。