You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 11:55:26