Lars
Lars

Reputation: 447

'Proptypes' is not defined

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.

Upvotes: 38

Views: 62200

Answers (7)

Aakash
Aakash

Reputation: 23727

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...

Upvotes: 0

testing
testing

Reputation: 79

Please Install prop-types

using this code:

npm install --save prop-types

Upvotes: 3

Ratul Bhattacharjee
Ratul Bhattacharjee

Reputation: 751

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

Upvotes: 65

jeff roussel
jeff roussel

Reputation: 81

I had the same problem on a project with eslint installed globally. I solved this case by installing eslint manualy in the project: npm i eslint --save

bye jeff

Upvotes: 4

Dan Mason
Dan Mason

Reputation: 2327

According to this issue comment.

It appears to be because you have installed eslint 4.x when you should just use the eslint version that is shipped with create-react-app. You should remove any eslint you have manually installed and use the one that comes with the repo.

Upvotes: 9

Anastasis Skotidas
Anastasis Skotidas

Reputation: 74

You can place the PropTypes just after the class (outside the class):

Routers.propTypes = {
   history: PropTypes.object.isRequired
}

Upvotes: -6

Farzam Babar
Farzam Babar

Reputation: 100

Please install the prop-types npm package - react 1.15 and greater on separate package is created.

Here to install package

Upvotes: -6

Related Questions