node.js - 为@typescript-eslint/parser 设置了解析错误“parserOptions.project”
问题描述
我创建了一个新的NestJS 项目,它是一个非常流行的 NodeJS 框架。但是我的 IDE(PhpStorm 2020.2-Beta)上有这个错误(见标题)并且 ESLint 根本不起作用。
我使用过 NestJS CLI:
nest new nestjs-micro
我似乎不是唯一遇到此问题的人,因此最好找到此问题的原因并一劳永逸地解决它。
我已经有一个未解决的问题,但我还没有答案,这真的很成问题。
如果有人知道如何解决问题并保持 ESLint / Prettier 与 PhpStorm 的集成,谢谢。
复制品
// .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
解决方案
FWIW 对我有用的这个错误是添加ignorePatterns: ['.eslintrc.js'],
到.eslintrc.js
文件中。这一行告诉eslint
忽略该.eslintrc.js
文件(因为它不包含在tsconfig
声明的项目中rootDir
)。
推荐阅读
- javascript - 基于 JQuery Prototype 的范围解析抛出 NaN 错误
- android - 如何在 android app auth 中为 Oauth 2.0 设置深层链接
- angular - 使用 cdkMonitorSubtreeFocus 角度聚焦事件顺序
- php - PHP、ZeroMQ、Socket io 和 Node Js 究竟是如何协同工作的
- python - 如何在 Python 中将数据类型对象添加到字典中
- css - Bootstrap 4:如何强制标签导航保持原位?
- javascript - 具有共享广告内容的静态页面
- python - win32api.getasynckeystate 在专注于其他应用程序时无法检测到键
- matlab - 如何在 Matlab 中对 m 和 x 都是向量的函数 besselj(m,x) 进行向量化?
- mysql - 如何根据多个最大列值选择一行?