[英]ESLint React Parsing Error
So I followed the instructions at guide.meteor.com to set up my package.json eslintConfig. 因此,我按照guide.meteor.com上的说明设置了package.json eslintConfig。
"eslintConfig": {
"plugins": [
"meteor"
],
"extends": [
"airbnb/base",
"plugin:meteor/recommended"
],
"rules": {
"meteor/eventmap-params": [
2,
{
"templateInstanceParamName": "instance"
}
],
"import/no-unresolved": [
2,
{
"ignore": [
"^meteor/"
]
}
],
"semi": [
"error",
"never"
]
}
}
It works fine until I try and use React. 在我尝试使用React之前,它可以正常工作。
main.js: main.js:
Meteor.startup(() => {
render(<App />, document.getElementById('render-target'))
})
That throws the error: [eslint] Parsing error: Unexpected token <
引发错误:
[eslint] Parsing error: Unexpected token <
I have the react plugin: 我有react插件:
"devDependencies": {
"eslint": "^2.9.0",
"eslint-config-airbnb": "^8.0.0",
"eslint-plugin-import": "^1.6.1",
"eslint-plugin-jsx-a11y": "^1.0.4",
"eslint-plugin-meteor": "^3.5.2",
"eslint-plugin-react": "^5.0.1"
}
I've tried following examples from Google but none of them helped. 我尝试了以下Google的示例,但没有一个有帮助。 I've tried adding 'react' and 'eslint-plugin-react' to the plugins bit and nothing changed.
我尝试将'react'和'eslint-plugin-react'添加到插件中,没有任何改变。 I'm gobsmacked the solution wasn't provided in the ESLint section of the meteor guide.
我很想知道该解决方案没有在流星指南的ESLint部分中提供。 Any assistance would be appreciated.
任何援助将不胜感激。
You don't need to install babel-eslint
. 您不需要安装
babel-eslint
。 Espree (native ESLint parser) fully supports ES6, ES7 and Object Rest/Spread. Espree(本机ESLint解析器)完全支持ES6,ES7和对象剩余/扩展。 The reason ESLint stopped parsing your file is because you haven't enabled
jsx
, so it will consider it as an incorrect syntax. ESLint停止解析文件的原因是因为您尚未启用
jsx
,因此它将认为它是不正确的语法。
{
"ecmaFeatures": {
"ecmaVersion": 6,
"sourceType": "module",
"jsx": true
}
}
Add the above snippet to your config file and it should start working. 将以上代码段添加到您的配置文件中,它应该开始工作。 For more information, you can read Specifying Parser Options
有关更多信息,您可以阅读指定解析器选项
Install babel-eslint
and to your .eslintrc
add "parser": "babel-eslint"
. 安装
babel-eslint
并在.eslintrc
添加"parser": "babel-eslint"
。 You're missing the ES6 transpiling so eslint just crashes. 您缺少ES6转换,因此eslint崩溃了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.