'Proptypes' is not defined

Lars picture Lars · Aug 15, 2017 · Viewed 35.8k times · Source

I'm setting up a new React with the help of: https://github.com/facebookincubator/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.

Answer

Ratul Bhattacharjee picture Ratul Bhattacharjee · Sep 20, 2018

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