Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find cause of Warning: PropTypes has been moved to a separate package

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.

enter image description here

like image 525
AdamG Avatar asked Jan 29 '23 12:01

AdamG


1 Answers

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)

enter image description here

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

like image 91
Hardik Modha Avatar answered Feb 01 '23 23:02

Hardik Modha