文章目录
1. 项目中遇到的问题
1.1 Failed to load plugin @typescript-eslint: Cannot find module ‘eslint-plugin-@typescript-eslint’
You need to upgrade your eslint version, in the error you can
see a bad prefix eslint-plugin- due to some const in
eslint/lib/config/plugins.js which was removed in later versions.
首先了解以下三个依赖:
eslint
: ESLint的核心代码@typescript-eslint/parser
:ESLint的解析器,用于解析typescript,从而检查和规范Typescript代码@typescript-eslint/eslint-plugin
:这是一个ESLint插件,包含了各类定义好的检测Typescript代码的规范
"@typescript-eslint/eslint-plugin": "1.2.0"
1.2 Cannot use JSX unless the ‘–jsx’ flag is provided.
在tsconfig.json中加入:
"jsx": "react",
1.3 TS7016: Could not find a declaration file for module
这个原因是我在ts中引入了js的内容,就会导致报错。
在tsconfig.json中加入:
"allowJs": true,