jon*_*nrz 4 reactjs eslint nextjs
这是我的 .eslintrc
{
"plugins": ["react"],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"env": {
"es6": true,
"browser": true,
"node": true,
"mocha": true
},
"extends": ["eslint:recommended", "plugin:react/recommended", "standard"],
"rules": {}
}
Run Code Online (Sandbox Code Playgroud)
这是我的组件:
class Index extends React.Component {
static async getInitialProps({ req }) {
....
}
}
Run Code Online (Sandbox Code Playgroud)
Eslint 抱怨 getInitialProps:
Parsing error: Unexpected token getInitialProps
Run Code Online (Sandbox Code Playgroud)
除了添加抑制注释之外,还有什么方法可以让 eslint 接受 getInitialProps 声明?
正如@Scott 在评论中指出的,解决方案是添加babel-eslint,我的最终 .eslintrc 如下:
{
"plugins": ["react"],
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"env": {
"es6": true,
"browser": true,
"node": true,
"mocha": true
},
"extends": ["eslint:recommended", "plugin:react/recommended", "standard"],
"rules": {}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
467 次 |
| 最近记录: |