'Proptypes'没有定义

Lar*_*ars 20 reactjs eslint

我在以下的帮助下建立了一个新的React:https://github.com/facebookincubator/create-react-app

但是,我遇到了一个问题.我收到以下linting错误'PropTypes' is not defined. (no-undef).

以下是导致此问题的代码:

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

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

...
Run Code Online (Sandbox Code Playgroud)

我尝试使用react/prop-types规则,但无济于事.

小智 26

由于反应15.5,PropTypes包含在一个单独的包中,'prop-types'.所以这一行会有所帮助

import PropTypes from 'prop-types'
Run Code Online (Sandbox Code Playgroud)

你可以在这里阅读更多


Pur*_*ory 8

根据这个问题评论.

这似乎是因为您已经安装了eslint 4.x应该只使用create-react-app附带的eslint版本.您应该删除手动安装的任何eslint,并使用repo附带的.