已为@tyescript-eslint/parser设置分析错误";parserOptions.project"; [英] Parsing error "parserOptions.project" has been set for @typescript-eslint/parser
本文介绍了已为@tyescript-eslint/parser设置分析错误";parserOptions.project";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个新的NestJS project,这是一个非常流行的NodeJS框架。但是我的集成开发环境(PhpStorm 2020.2-测试版)上出现此错误(请参阅标题),并且eSLint根本不起作用。
我使用过NestJS CLI:
nest new nestjs-micro
我似乎不是唯一有此问题的人,所以最好找出此问题的原因并一劳永逸地解决它。
我已经有一个未解决的issue,但是我还没有得到答复,这真的很有问题。
如果任何人对如何解决此问题并保持与PhpStorm的ESLint/更美观的集成有什么想法,谢谢。
转载
// .eslintrc.js
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/@typescript-eslint',
],
root: true,
env: {
node: true,
jest: true,
},
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
// tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true
}
}
版本
Typescript: 3.7.4
Node: 14.3.0
ESLint: 7.1.0
@typescript-eslint/parser: 3.0.2
Yarn: 1.22.4
推荐答案
我算出来了。
当TypeScript没有要包括以进行编译的文件时,会发生该错误。
最简单的解决方案是创建一个tsconfig.build.json文件,并在其中指定以下参数:
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "dist/**/*spec.ts"],
"include": ["src/**/*", ".eslintrc.js"]
}
以上示例适用于NestJS,但应该适用于其他项目。
最令人惊讶的是,这只是PHPStorm(内部版本)上显示的一个错误,它工作得很好。
这篇关于已为@tyescript-eslint/parser设置分析错误";parserOptions.project";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文