create-react-app: Failed to compile after install eslint locally (propTypes is not defined)

If you are reporting a bug, please fill in below. Otherwise feel free to remove this template entirely.

Can you reproduce the problem with latest npm?

Yes, on OSX Sierra.

Description

create-react-app test
cd test/
yarn add eslint
yarn start

Expected behavior

Should compile successfully.

Actual behavior

yarn start failed to compile, showing error: propTypes is not defined

image

Environment

Run these commands in the project folder and fill in their results:

  1. npm ls react-scripts (if you haven’t ejected):
test@0.1.0 /Users/dinhquangtrung/Desktop/test
└── react-scripts@1.0.7
  1. node -v:
v8.1.0
  1. npm -v:
5.0.3

Then, specify:

  1. Operating system: OSX Sierra
  2. Browser and version: (any)

Reproducible Demo

Repo: https://github.com/trungdq88/create-react-app-issue Travis Build: https://travis-ci.org/trungdq88/create-react-app-issue/builds/242429125

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 20 (14 by maintainers)

Most upvoted comments

@trungdq88 React removed PropTypes since version 15.5, see here you can use prop-types package for it.

I got that same error on a state variable defined at class level. I guess it is the same issue, isn’t it ?

export default class MyComponent extends Component {
  state = {
    open: true
  }
Failed to compile.

./src/components/MultiSelect/index.js
  Line 7:  'state' is not defined  no-undef

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

bye jeff

Seem to only happen if installed eslint 4.x.

If you mean that you installed eslint locally in your project, this is not really supported. I know that people do this, but we don’t recommend it.

You don’t need to install it locally, it will work out of the box. Installing it locally can mess up the versions, which is what probably happened.