eslint报错怎么解决:Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser
运行以下命令就会获得报错
eslint src --ext .js,.ts,.vue
报错内容
0:0 error Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser.
The file was not found in any of the provided project(s): src\views\TagDetail.vue
eslint的配置文件
// eslint.config.js
import vuePlugin from 'eslint-plugin-vue';
import tsPlugin from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import globals from 'globals';
export default [
{
ignores: ['node_modules', 'dist', '*.local', 'public'],
},
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
parser: tsParser,
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: './tsconfig.eslint.json',
},
},
plugins: {
'@typescript-eslint': tsPlugin,
},
rules: {
// ESLint 基础规则
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
// TypeScript 规则
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/no-explicit-any': 'off',
},
},
{
files: ['*.vue'],
plugins: { vue: vuePlugin },
rules: {
// Vue 规则
'vue/multi-word-component-names': 'off',
'vue/no-multiple-template-root': 'off',
'vue/script-setup-uses-vars': 'error',
},
},
];
tsconfig的配置文件
// tsconfig.eslint.json
{
"include": [
"src/**/*.ts",
"src/**/*.vue",
"src/**/*.js",
"eslint.config.js"
],
"extends": "./tsconfig.json"
}
src\views\TagDetail.vue文件存在
不知道如何尝试,期望能正常检查vue文件
问题:原配置让所有文件(包括 Vue 文件)都使用 TypeScript parser,但 TypeScript parser 不知道如何处理 Vue 文件的特殊语法。
解决方案: