[英]ESlint: Parsing error: Unexpected token <
I have this function:我有这个 function:
import React from 'react';
import FilterList from './Filter/FilterList';
export default function Sidebar() {
return (
<div>
<FilterList />
</div>
);
}
And included these packages:并包括这些包:
"dependencies": {
"bootstrap": "^3.3.7",
"font-awesome": "^4.7.0",
"i18n-react": "^0.4.0",
"react": "^15.6.1",
"react-bootstrap": "^0.31.2",
"react-dom": "^15.6.1",
"react-fontawesome": "^1.6.1",
"react-router-dom": "^4.1.2",
"rxjs": "^5.4.3",
"superagent": "^3.5.2",
"webpack": "^3.5.4"},
"devDependencies": {
"eslint": "^4.4.1",
"eslint-config-airbnb-base": "^11.3.1",
"eslint-plugin-import": "^2.7.0",
"nwb": "0.18.x",
"nwb-less": "^0.6.0",
"yaml-loader": "^0.5.0"},
But when running lint I get this error: error Parsing error: Unexpected token <但是在运行 lint 时出现此错误:error Parsing error: Unexpected token <
my.eslintrc file: my.eslintrc 文件:
module.exports = {
"extends": "airbnb-base",
"plugins": [
"import"
]};
What am I doing wrong?我究竟做错了什么?
You are getting this error because eslint don't know how to handle JSX syntax, and you need eslint-plugin-react
for this.您收到此错误是因为 eslint 不知道如何处理 JSX 语法,因此您需要eslint-plugin-react
。
But you are also missing other plugins required for airbnb-eslint-config to work.但是您还缺少 airbnb-eslint-config 工作所需的其他插件。 Do what they say in docs which is:做他们在文档中所说的:
npm info "eslint-config-airbnb@latest" peerDependencies
and install printed dependencies (as dev dependencies).并安装打印的依赖项(作为开发依赖项)。
As of today I get this list:截至今天,我得到了这个列表:
{ eslint: '^3.19.0 || ^4.3.0',
'eslint-plugin-jsx-a11y': '^5.1.1',
'eslint-plugin-import': '^2.7.0',
'eslint-plugin-react': '^7.1.0' }
If you are using nmp5+
, one shortcut would be:如果您使用的是nmp5+
,一种快捷方式是:
npx install-peerdeps --dev eslint-config-airbnb
The -peerdeps
refers to all the dependences. -peerdeps
指的是所有依赖项。
If every peer dependency is added and you still get this error, be sure to check that your eslint config has the following options:如果添加了每个对等依赖项并且您仍然收到此错误,请务必检查您的 eslint 配置是否具有以下选项:
"parserOptions": {
"ecmaFeatures": {
"jsx": true,
"modules": true
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.