React 构建中 CSS Minimizer 插件出现未知单词错误
由于 CSS Minimizer 插件的“未知单词”错误,React 构建失败。当我运行 npm run build
时,它不断失败!
编译失败。
来自 Css Minimizer 插件的 static/css/main.d3e3749c.css static\css\main.d3e3749c.css:698:13: 未知单词 [: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"
}
}
The React build failed due to the CSS Minimizer plugin's "Unknown word" error. When I run npm run build,
it continuously fails!
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]
My Node version is v16.14.0. Everything works well in npm start,
but the build fails. Maybe this is due to PostCSS. I tried downgrading the version for the same, but it didn't work.
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"
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题,就我而言,错误是由顺风 JIT 模式引起的。
我的一个文件中有这样的样式:
top-[${positionFromTop}]
,这导致了错误。
要查找错误原因,您应该使用 tailwind CLI 运行
npx tailwindcss -i ./src/{YOUR_MAIN_CSS_FILE}.css -o ./dist/output.css --watch
命令,然后检查 output.css 是否有任何语法错误。然后只需修复导致语法错误的样式即可。I had the same problem and, in my case, the error was caused by tailwind JIT mode.
I had a style like:
top-[${positionFromTop}]
in one of my files, which caused the error.
To find the cause of your error, you should run the
npx tailwindcss -i ./src/{YOUR_MAIN_CSS_FILE}.css -o ./dist/output.css --watch
command with the tailwind CLI, and then check the output.css for any syntax errors. Then just fix the style that causes the syntax error.我正在从 tailwindcss 类中的状态传递数据。
top-[${positionFromTop}]
解决方案:不要使用任何花哨的 CSS。
I was passing data from state in tailwindcss class.
top-[${positionFromTop}]
Solution: Don't use any fancy CSS.