什么是IntelliJ IDE家族中的“解析错误:已为@typescript-eslint/parser设置了“parserOptions.project”。”错误的含义?

8 浏览
0 Comments

什么是IntelliJ IDE家族中的“解析错误:已为@typescript-eslint/parser设置了“parserOptions.project”。”错误的含义?

当我打开.vue文件时,在我的IntelliJ IDEA中出现以下错误:

解析错误:“parserOptions.project”已为@typescript-eslint/parser设置。

文件与您的项目配置不匹配:XX\XX\CurrentFile.vue。

该文件必须至少包含在提供的一个项目中。

enter image description here

当然,如果您能教我解决方案,我将很高兴,但首先我想知道它的意思和为什么会出现这个错误。

我怀疑这是某种错误或不准确的错误消息。根据实验得知:

  1. 有时出现,有时不出现。
  2. 更新eslint时总是出现。
  3. 如果对一些.vue文件从控制台运行eslint,eslint将正确执行。因此,看起来不是eslint的错误。

我的Eslint配置(YAML):

parser: vue-eslint-parser

parserOptions:

parser: "@typescript-eslint/parser"

sourceType: module

project: tsconfig.json

tsconfigRootDir: ./

extraFileExtensions: [ ".vue" ]

env:

es6: true

browser: true

node: true

plugins:

- "@typescript-eslint"

- vue

rules:

// ...

TypeScript设置:

{

"compilerOptions": {

"target": "ES2017",

"module": "CommonJS",

"moduleResolution": "node",

"esModuleInterop": true,

"allowSyntheticDefaultImports": true,

"sourceMap": true,

"experimentalDecorators": true,

"skipLibCheck": true,

"strict": true,

"noUnusedParameters": true,

"noImplicitReturns": true,

"importsNotUsedAsValues": "preserve", // Limitation of the transpileOnly mode from ts-loader for .vue files.

"baseUrl": "./",

"paths": {

// ...

}

}

}

0
0 Comments

问题出现的原因是在IntelliJ IDE家族中出现了“Parsing error: 'parserOptions.project' has been set for @typescript-eslint/parser.”错误。该错误的解决方法是将文件添加到tsconfig的“include”数组中。

解决方法如下:

您需要将文件添加到tsconfig的“include”数组中:

"include": [

"path/to/src/**/*"

]

为什么错误没有提到“include”数组?

这个错误没有具体提到“include”数组,但它清楚地表示错误是与包含有关的。

为什么TypeScript配置会影响到eslint?

TypeScript配置会影响到typescript-eslint,因为根据配置不同,代码检查器可能会有不同的解析方式。例如,如果一个文件没有包含在tsconfig中,typescript-eslint就不知道应该将其解析为TypeScript。

如果文件已经包含在内,但是只有在添加新文件时才出现这个错误呢?

0