Skip to main content

Typescript Eslint QA

项目配置完 eslint之后报👇错误

Parsing error: ImportDeclaration should appear when the mode is ES6 and in the module context

ts-eslint-parsing-error.png

解决办法:

// .eslintrc
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
// //也就是ES6语法支持的意思
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"modules": true
}
},
"plugins": ["@typescript-eslint"],
// ...
}

参考

eslint issue 55

eslint issue 56

eslint issue 4344

eslint specifying-parser-options