create-react-app 构建错误“需要伪类或伪元素。”

She*_* Yu 5 postcss create-react-app

我使用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.
Run Code Online (Sandbox Code Playgroud)

不幸的是,这不是一个非常有用的错误。谷歌搜索似乎找到了有关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.
Run Code Online (Sandbox Code Playgroud)

小智 2

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

例如:

**header nav li:last-child {
    margin-right: 0;
}**
Run Code Online (Sandbox Code Playgroud)

被写为:

**header nav li: last-child {
    margin-right: 0;
}**
Run Code Online (Sandbox Code Playgroud)