create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

Getting the 'propTypes' is not defined no-undef

Open shyam2794 opened this issue 9 years ago • 5 comments

hi all ,

I created my react app using create-react-app . It works fine .

 But I am getting the error message **Getting the 'propTypes' is not defined no-undef** ,  if i try to use propTypes and came to know that it is coz of the eslint 4.* , do anyone know whether this is issue resolved or not .

shyam2794 avatar Nov 04 '17 12:11 shyam2794

You have barely provided any details so it's hard to answer.

But installing a different version of ESLint into a project generated by CRA is not supported, if that's what you did. Otherwise we'll need an example project to investigate.

gaearon avatar Nov 04 '17 12:11 gaearon

@gaearon i have not installed ESLint locally , it comes with the default create-react-app , i just did the following steps

install -g create-react-app -> this i have done globally so that i can create the App anywhere within my computer . Then i just created a new directory for eg let say Test - > within this i executed create-react-app $projectname

Then cd $projectname and npm start . I havent done anything other than the above .This is my code ` import React, { Component } from 'react'; import PropTypes from 'prop-types'; import './App.css';

class App extends Component { render() { return (

The App name is : {this.props.name}

The App id is : {this.props.id}

The App Details is : {this.props.Details}

The App object is : {this.props.object.obj1}

); } }

App.propTypes = { name: PropTypes.string, id: PropTypes.number, Details: PropTypes.string, object: propTypes.object }

App.defaultProps = { name: "React App", id: 25, Details: "This is my first App", object: { obj1: "This is obj one", obj2: "This is obj one", obj3: "This is obj one" } }

export default App; `

shyam2794 avatar Nov 04 '17 13:11 shyam2794

Then the error is legit. You have a line that says:

  object: propTypes.object

but there is no propTypes. There's only PropTypes (capital "P") which you imported.

This is exactly what the error says: propTypes is not defined.

To fix, change it to:

  object: PropTypes.object

gaearon avatar Nov 04 '17 13:11 gaearon

@gaearon Thanks a lot mate .

shyam2794 avatar Nov 04 '17 13:11 shyam2794

Glad it helped! Let us know if you bump into more issues.

gaearon avatar Nov 04 '17 13:11 gaearon