什么是“解析错误:已为 @typescript-eslint/parser 设置了“parserOptions.project”。 IntelliJ IDE 系列中的错误?
Posted
技术标签:
【中文标题】什么是“解析错误:已为 @typescript-eslint/parser 设置了“parserOptions.project”。 IntelliJ IDE 系列中的错误?【英文标题】:What means 'Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.' error in IntelliJ IDEs family? 【发布时间】:2020-12-31 20:45:58 【问题描述】:当我打开 .vue
文件时,我的 IntelliJ IDEA 中出现以下错误:
Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: XX\XX\CurrentFile.vue.
The file must be included in at least one of the projects provided.
当然,如果您教我解决方案,我会很高兴,但首先我知道它的含义以及它出现的原因。
我怀疑这是某种错误或不准确的错误消息。实验知道什么:
-
有时会出现,有时 - 不会。
更新 eslint 时总是出现。
如果从控制台运行
eslint
对一些.vue
文件,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":
// ...
【问题讨论】:
您能否分享一个指向显示该问题的 GitHub 存储库的链接? 如果你不能分享上面提到的所有代码,你能添加你的tsconfig.json
吗?
@tomdaly 我在我的问题中添加了 TypeScript 配置。
【参考方案1】:
您需要将文件添加到 tsconfig 中的 include
数组中:
"include": [
"path/to/src/**/*"
]
来源:Github 和 ***
【讨论】:
感谢您的解决方案!但是请告诉我: 1) 为什么错误没有引用include
数组? 2)为什么打字稿配置会影响@typescrit-eslint?
The file must be included in at least one of the projects provided
=> 它没有专门讨论include
数组,但它明确指出错误是指包含
Typescript 配置会影响typescript-eslint
,因为 linter 可能会根据配置进行不同的解析。例如,如果一个文件不包含在 tsconfig 中,typescript-eslint 不知道是否应该将其解析为 typescript
好的,问题已经用完了。非常感谢您对本文的贡献。
如果包含文件,并且这个错误似乎只在添加新文件时发生?以上是关于什么是“解析错误:已为 @typescript-eslint/parser 设置了“parserOptions.project”。 IntelliJ IDE 系列中的错误?的主要内容,如果未能解决你的问题,请参考以下文章