我无法找到一个我错的地方。
我的.eslintrc
{
"extends": "eslint:recommended",
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true
},
"plugins": [
"react"
],
"rules": {
"no-console": 0,
"new-cap": 0,
"strict": 0,
"no-underscore-dangle": 0,
"no-use-before-define": 0,
"eol-last": 0,
"quotes": [2, "single"],
"jsx-quotes": 1,
"react/jsx-no-undef": 1,
"react/jsx-uses-react": 1,
"react/jsx-uses-vars": 1
}
}
我的webpack.config部分关于lint:
preLoaders: [
{
test: /\.js$/,
loaders: ['eslint'],
include: [
path.resolve(__dirname, "src"),
],
}
],
我的组件
import React, { PropTypes, Component } from 'react'
export default class User extends Component {
render() {
const { name } = this.props
return <div>
<p>Hello, {name}!</p>
</div>
}
}
User.propTypes = {
name: React.PropTypes.string.isRequired
}
我有例外: 1:17错误“PropTypes”已定义,但从未使用过no-unused-vars
嗯,我做错了什么?P.S。使用babel5 - 一切正常。
答案 0 :(得分:13)
User.propTypes = {
name: React.PropTypes.string.isRequired
}
您已将React.PropTypes
导入为PropTypes
,因此在这种情况下,只需将其更改为name: PropTypes.string.isRequired
(或删除顶部的PropTypes导入)