如何查找警告原因:PropTypes 已移至单独的包 [英] How to find cause of Warning: PropTypes has been moved to a separate package

查看:29
本文介绍了如何查找警告原因:PropTypes 已移至单独的包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我收到警告警告:PropTypes 已移至单独的包."如何找到仍在使用它的 npm 包?该警告未提供有关导致该警告的文件或包的任何详细信息.

解决方案

React 从他们的主包中弃用了 propTypes,因此你不能使用 React.PropTypes.当您使用 React.PropTypes 时,它会给您一个警告,但是当您使用 prop-types 包中的 propTypes 时,您很好.

就是这样:)

您可以使用这些知识通过以下命令查找正在使用它的 npm 包列表.

find ./node_modules -type f -print0 |xargs -0 grep 'PropTypes' |剪切 -d/-f3 |排序 |唯一|xargs -I{} grep -L 'prop-types' ./node_modules/{}/package.json

上面的命令会找到所有文件中包含 PropTypes 字的 npm 包,然后查看该包的 package.json 文件进行检查是否包含 prop-types 包.如果 prop-types 包丢失,则打印该包的路径.

PS:我不是 bash 专家,所以我从

PPS:答案假设您使用的是 Unix 机器.

If I get the warning "Warning: PropTypes has been moved to a separate package." How can I locate which npm package is still using it? The warning doesnt offer any details about what file or package is causing it.

解决方案

React deprecated the usage of propTypes from their main package so you can't use React.PropTypes. When you use React.PropTypes it gives you a warning but when you use propTypes from prop-types package you are good.

That's It :)

You can use this knowledge to find the list of npm packages which are using it through the following command.

find ./node_modules -type f -print0 | xargs -0 grep 'PropTypes' | cut -d/ -f3 | sort | uniq | xargs -I{} grep -L 'prop-types' ./node_modules/{}/package.json

The above command will find all the npm packages having PropTypes word present in any of their files, then it looks into the package.json file of that package to check whether the prop-types package is included or not. If prop-types package is missing then it prints the path of that package.

PS: I'm no bash expert so I've taken little help from this serverfault answer. (To find the unique npm packages containing the PropTypes word)

PPS: The answer assumes that you are using a Unix machine.

这篇关于如何查找警告原因:PropTypes 已移至单独的包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆