【问题标题】:create-react-app build error "Expected a pseudo-class or pseudo-element."create-react-app 构建错误“需要一个伪类或伪元素。”
【发布时间】:2019-04-10 15:49:26
【问题描述】:

我使用 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.

【问题讨论】:

  • 我被同样的问题困扰了一段时间。找不到解决办法。
  • 你发现了吗?我在使用 Vue 的 electron-builder 插件时遇到了同样的问题

标签: create-react-app postcss


【解决方案1】:

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

例如:

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

写成:

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

【讨论】:

    【解决方案2】:

    表示项目中导入的其中一个css文件存在语法错误。例如 - //

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-16
      • 2011-03-08
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-13
      相关资源
      最近更新 更多