无法读取未定义的 CompileError 的属性“类型”:始于未定义的 CSS 选择器“npm run build”

IT技术 reactjs npm
2021-05-26 22:04:34

当我npm run build在我的create-react-app项目中做时,它失败并且登录不是很有帮助。

这里 -> npm 日志的图像

这是文本格式的问题。

> react-scripts build

Creating an optimized production build...
Failed to compile.

Cannot read property 'type' of undefined
CompileError: Begins at CSS selector undefined


npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! card_builder@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the card_builder@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in

我的应用程序在开发模式下运行良好(即在npm start

这是代码沙箱网址的链接-> https://codesandbox.io/s/cant-read-propery-type-of-undefined-problem-with-react-scripts-build-6riyp

使用 create-react-app 构建

1个回答

这种错误很可能来自某个地方的空 CSS 规则。它可能来自依赖项,所以这可能会变得棘手。

要做的第一件事是尝试从项目中一个一个地删除 css 文件,以找出问题所在。如果你找不到它,那么它来自一个依赖项,你最好的办法是empty-rules从 CSSLint 或你正在使用的 linter 中删除规则。

资源:https : //github.com/CSSLint/csslint/wiki/Disallow-empty-rules