在以下代码的第 4 行,ESLint 给我一个解析错误:
Unexpected token =
我想知道为什么会这样?代码运行正常。我做错了什么?
import { Component, PropTypes } from 'react';
export default class MainApp extends Component {
static propTypes = {
children: PropTypes.any.isRequired
}
componentWillMount() {
require('./styles/main.styl');
}
render() {
return (
<div>
{this.props.children}
</div>
);
}
}
最佳答案
我能够通过以下方式解决此问题:
1) 安装babel-eslint
$ npm i --save-dev babel-eslint
或
$ yarn add babel-eslint --dev
2) 配置 ESLint 以使用 babel-eslint 作为你的解析器
只需将 "parser": "babel-eslint",
添加到您的 .eslintrc 文件即可。
示例 .eslintrc 以使用 babel-eslint
和带有一些自定义规则的 airbnb 配置:
{
"parser": "babel-eslint",
"extends": "airbnb",
"rules": {
"arrow-body-style": "off",
"no-console": "off",
"no-continue": "off"
}
}
关于javascript - 神秘的 ESLint 解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34125141/