创建 react 应用程序构建错误 "Expected a pseudo-class or pseudo-element."

标签 create-react-app postcss

我使用 create-react-app 创建了一个应用程序并且在尝试构建生产优化版本时遇到错误 yarn build :

> yarn build help
yarn run v1.9.4
$ react-scripts build help
Creating an optimized production build...
Failed to compile.

Expected a pseudo-class or pseudo-element.

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

不幸的是,这不是一个非常有用的错误。谷歌搜索似乎找到了关于 postcss 的内容但我不确定这与 create-react-app 有什么关系,或者如何解决这个问题。

有没有人遇到过类似的问题?

请注意,该应用程序在开发模式下可以正常编译:
Compiled successfully!

You can now view note-app in the browser.

  Local:            http://localhost:3000/
  On Your Network:  http://192.168.0.54:3000/

Note that the development build is not optimized.
To create a production build, use yarn build.

最佳答案

错误消息“需要伪类或伪元素。”可能会在导入的 CSS 文件之一中提示伪类的一些语法错误。

例如:

**header nav li:last-child {
    margin-right: 0;
}**

被写成:
**header nav li: last-child {
    margin-right: 0;
}**

关于创建 react 应用程序构建错误 "Expected a pseudo-class or pseudo-element.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53185678/

相关文章:

reactjs - 支架和create-react-app停止工作

reactjs - 如何使用 Tailwind CSS 更改日历图标的颜色?

css "vertical for-loop"- css 网格的助手 - 字符串重复/构建

node.js - Create-react-app 失败,出现错误 : node incompatible with css-loader

reactjs - 在 react 中提交表单后重定向到网站

reactjs - create-react-app 自 4.0.1 版起不起作用

css - Webpack 和 PostCSS 单独设置

reactjs - postcss 7.0.0 - 8.2.9 严重性 : moderate Regular Expression Denial of Service

node.js - 用 postcss 观察多个 css 文件并输出一个 bundle.css

webpack - 如何创建没有 PWA 功能的 CRA 项目?