ESLint Parsing error: Unexpected token

NPM run Lint Reports when esLint checks:

  • Parsing error: Unexpected token…
  • Parsing error: The keyword ‘import’ is reserved

Error.

At that time. Eslintrc. Js

// .eslintrc.js文件
"parserOptions": {
  "parser": "babel-eslint",
}
Copy the code

Parsing error: The keyword ‘import’ is reserved. Parsing error: Parsing error The Unexpected token problem still exists.

// .eslintrc.js文件
"parserOptions": {
  "sourceType": "module",
  "ecmaVersion": 2020,
  "parser": "babel-eslint",
},
Copy the code

It turns out that the following solution solves the problem: add'parser': '@typescript-eslint/parser'Remember to install dependenciesnpm install @typescript-eslint/parser --save-dev.

The modified.eslintrc.js

// .eslintrc.js文件
'parser': '@typescript-eslint/parser',
'parserOptions': {
  'parser': 'babel-eslint',
},
Copy the code