当我在我的应用中工作时,我注意到我有 80 个漏洞,主要是因为对等版本,比如一个要求 react 16.8.0,我有 17.0.1 之类的,但另一个说:
Moderate Regular Expression Denial of Service
Package postcss
Patched in >=8.2.10
Dependency of react-scripts
Path react-scripts > postcss-preset-env >
postcss-replace-overflow-wrap > postcss
More info https://npmjs.com/advisories/1693
所以我搜索并更新了所有内容。现在我有 0 个漏洞,但我的应用程序没有运行,所以看起来它无论如何都没有漏洞。 当我运行它时,它向我展示了很多这样的消息(它只改变了在这种情况下它说“伪类任何”的部分):
postcss-pseudo-class-any-link: postcss.plugin was deprecated. Migration guide:
https://evilmartians.com/chronicles/postcss-8-plugin-migration
然后它说:
./src/App.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-4-1!./node_modules/postcss-loader/src??postcss!./src/App.css)
TypeError: Cannot read property 'unprefixed' of undefined
答案 0 :(得分:2)
问题是许多库(例如 react-scripts)尚未从 PostCSS 7 更新到 PostCSS 8。
出于同样的原因,我也做了一个 forced update of some of my dependencies,并且在 React 构建期间,看到了这条消息:
Post-css-modules-values: postcss.plugin was deprecated. Migration guide:
https://evilmartians.com/chronicles/postcss-8-plugin-migration
相同的消息还提到了以下所有内容,参考迁移指南:
postcss-modules-local-by-default, modules-extract-imports, postcss-modules-scope, postcss-import-parser, postcss-icss-parser, postcss-url-parser, postcss-flexbugs-fixes, autoprefixer, postcss-ttribute-case-insensitive, css-blank-pseudo, postcss-color-functional-notation, postcss-color-gray, postcss-color-hex-alpha, postcss-color-mod-function, postcss-color-rebeccapurple, postcss-custom-media,
postcss-custom-properties, postcss-custom-selectors, postcss-dir-pseudo-class, postcss-double-position-gradients, postcss-env-fn, postcss-focus-visible, postcss-focus-within, postcss-font-variant, postcss-gap-properties, css-has-pseudo, postcss-image-set-function
然后我得到一个错误(几乎与操作相同),涉及 Bootstrap 和 PostCSS:
./node_modules/bootstrap/dist/css/bootstrap.min.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-4-1!./node_modules/postcss-loader/src??postcss!./node_modules/bootstrap/dist/css/bootstrap.min.css)
TypeError: Cannot read property 'unprefixed' of undefined
许多包都包含 PostCSS 作为依赖项。
看看 the docs about updating plugins for using PostCSS 8.0,似乎等到我们项目中的包更新到 PostCSS 8.0 API,或者根据 PostCSS 的 8.0 更新文档手动分叉和编辑它们,可能是某些项目的唯一选择。
比这更好的答案将不胜感激。