NX Workspace中NestJS-Angular项目nx lint报错:parserOptions.project配置无效
解决NX Workspace中
nx lint的TypeScript类型检查器配置错误 问题根源
你配置的parserOptions.project使用了绝对路径/apps/client/tsconfig.*?.json,ESLint会从系统根目录开始解析这个路径,而非你的项目目录,导致无法找到正确的tsconfig文件。
修正方案
修改apps/client/.eslintrc.json中TypeScript规则块的parserOptions.project为相对路径:
{ "extends": ["../../.eslintrc.json"], "ignorePatterns": ["!**/*"], "overrides": [ { "files": ["*.ts"], "parserOptions": { // 使用相对路径指向当前目录下的tsconfig文件 "project": ["./tsconfig.app.json", "./tsconfig.spec.json"] }, "extends": [ "plugin:@nrwl/nx/angular", "plugin:@angular-eslint/template/process-inline-templates" ], "rules": { "@angular-eslint/directive-selector": [ "error", { "type": "attribute", "prefix": "learning", "style": "camelCase" } ], "@angular-eslint/component-selector": [ "error", { "type": "element", "prefix": "learning", "style": "kebab-case" } ], "no-empty-function": "off", "@typescript-eslint/no-empty-function": "off", "@angular-eslint/no-empty-lifecycle-method": "off" } }, { "files": ["*.html"], "extends": ["plugin:@nrwl/nx/angular-template"], "rules": {} } ] }
如果需要用通配符匹配所有tsconfig文件,也可以简化为:
"parserOptions": { "project": ["tsconfig.*.json"] }
额外排查步骤
- 确认
apps/client/目录下存在tsconfig.app.json和tsconfig.spec.json(NX生成的Angular项目默认包含这两个文件) - 检查根目录
.eslintrc.json是否存在覆盖子项目parserOptions的配置 - 清理NX缓存后重新执行lint:
nx reset nx lint client
内容的提问来源于stack exchange,提问作者AngularNest-beginner
相关产品推荐
相关产品推荐

