Can't find variable: PropTypes

Viewed 4398

I am trying some react native code.

Added props for my component based on the instructions given in this blog.

End up in the error, Can't find variable: PropTypes Found the same question in github but it was closed without any answers

Couldn't get any clues.

3 Answers

You need to do install prop-types with npm install --save prop-types or yarn add prop-types and then add this to your code:

import PropTypes from 'prop-types';
  • Make sure prop-types is installed:
    npm install --save prop-types

  • Make sure the following line is added in the file where the error originated
    import PropTypes from 'prop-types'; .

Ok, so I was having a similar issue when configuring my react router (react-router-dom), then I realized I used YARN to add react, react-dom and prop-types, and NPM to add the react-router-dom, then I got suspicious it was this the problem and I:

removed it with: npm uninstall react-router-dom

and installed it with: yarn add react-router-dom --dev

and it stopped giving me the error / fixed it.

Related