'Proptypes' is not defined

Viewed 51287

I'm setting up a new React with the help of: Create React App

However, I'm running into a linting issue. I'm receiving the following linting error 'PropTypes' is not defined. (no-undef).

Here is the code that is causing the issue:

import React, { Component } from 'react';
import PropTypes from 'prop-types';

class Routers extends Component {
  static propTypes = {
    history: PropTypes.object.isRequired
  };

...

I tried playing around with the react/prop-types rule, but to no avail.

7 Answers

Since react 15.5, PropTypes is included in a separate package, 'prop-types'. So this line will help

import PropTypes from 'prop-types'

You can read more here

Please Install prop-types

using this code:

npm install --save prop-types

If you're using <script> tags; you can add this tag:

<script src="https://cdnjs.cloudflare.com/ajax/libs/prop-types/15.7.2/prop-types.min.js" integrity="sha512-ssNhh7jlzc+K93ckIlSXFHHz6fSFv0l619WOv8xbFNRbFOujbasb42LVMOggDrQR1ScJncoWb+KAJx1uF3ipjw==" crossorigin="anonymous"></script>

You can get the minified/non-minified and other version here

Good Luck...

Related