简体   繁体   English

angular 项目中 ng lint 期间未处理的异常

[英]Unhandled exception during ng lint in angular project

I am trying to run ng lint on my angular project.我正在尝试在我的 angular 项目上运行ng lint I migrated an Angular project from TSLint to ESLint, but when I run ng lint I get this error message:我将 Angular 项目从 TSLint 迁移到 ESLint,但是当我运行ng lint时,我收到以下错误消息:

An unhandled exception occurred: Invalid lint configuration. Nothing to lint.

What could have gone wrong with the configuration?配置可能出了什么问题?

ng version : Angular CLI: 11.2.9, Angular: 11.2.0 ng 版本:Angular CLI:11.2.9,Angular:11.2.0

.eslintrc.json .eslintrc.json

{
  "root": true,
  "ignorePatterns": [
    "projects/**/*"
  ],
  "overrides": [
    {
      "files": [
        "*.ts"
      ],
      "parserOptions": {
        "project": [
          "tsconfig.json",
          "e2e/tsconfig.json"
        ],
        "createDefaultProgram": true
      },
      "extends": [
        "plugin:@angular-eslint/recommended",
        //"plugin:@typescript-eslint/recommended", TODO: check warnings
        "plugin:@angular-eslint/ng-cli-compat",
        "plugin:@angular-eslint/ng-cli-compat--formatting-add-on",
        "plugin:@angular-eslint/template/process-inline-templates"
      ],
      "rules": {
        "@angular-eslint/no-empty-lifecycle-method": "off",
        "@angular-eslint/component-selector": [
          "error",
          {
            "type": "element",
            "prefix": "app",
            "style": "kebab-case"
          }
        ],
        "@typescript-eslint/naming-convention": [
          "error",
          {
            "selector": "variable",
            "modifiers": ["const", "exported"],
            "types": ["function"],
            "format": ["camelCase"]
          },
          {
            "selector": "variable",
            "modifiers": ["const","exported"],
            "types": ["string", "number", "array", "boolean"],
            "format": ["UPPER_CASE"]
          }
        ],

        "@angular-eslint/directive-selector": [
          "error",
          {
            "type": "attribute",
            "prefix": "app",
            "style": "camelCase"
          }
        ]
      }
    },
    {
      "files": [
        "*.html"
      ],
      "extends": [
        "plugin:@angular-eslint/template/recommended"
      ],
      "rules": {}
    }
  ]
}

angular.json angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "libs-common-angular": {
      "root": "projects",
      "sourceRoot": "projects/src",
      "projectType": "library",
      "prefix": "lib",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:ng-packagr",
          "options": {
            "tsConfig": "libs/tsconfig.lib.json",
            "project": "libs/package.json"
          }
        ,
          "configurations": {
            "production": {
              "tsConfig": "projects/tsconfig.lib.prod.json"
            }
          }
},
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "libs/src/test.ts",
            "polyfills": "libs/polyfills.ts",
            "tsConfig": "libs/tsconfig.spec.json",
            "karmaConfig": "libs/karma.conf.js"
          }
        },
        "lint": {
          "builder": "@angular-eslint/builder:lint",
          "options": {
            "lintFilePatterns": [
              "src/**/*.ts",
              "src/**/*.html"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "libs-common-angular"
}

package.json package.json

{
  "name": "libs-common-angular",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "pre-release": "npm --prefix libs version patch && ng build libs-common-angular",
    "release": "npm --prefix libs version patch && ng build libs-common-angular && npm publish --@owi dist/libs-common-angular"
  },
  "private": false,
  "dependencies": {
    "@angular/animations": "^11.2.0",
    "@angular/cdk": "^11.2.0",
    "@angular/common": "~11.2.0",
    "@angular/compiler": "~11.2.0",
    "@angular/core": "~11.2.0",
    "@angular/flex-layout": "^11.0.0-beta.33",
    "@angular/forms": "~11.2.0",
    "@angular/material": "^11.2.0",
    "@angular/material-moment-adapter": "^11.2.0",
    "@angular/platform-browser": "~11.2.0",
    "@angular/platform-browser-dynamic": "~11.2.0",
    "@angular/router": "~11.2.0",
    "core-js": "^2.6.12",
    "moment": "^2.29.1",
    "rxjs": "~6.6.3",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1102.9",
    "@angular/cli": "~11.2.9",
    "@angular/compiler-cli": "~11.2.0",
    "@types/jasmine": "~3.6.0",
    "@types/node": "^12.11.1",
    "codelyzer": "^6.0.0",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~6.1.1",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "karma-phantomjs-launcher": "^1.0.0",
    "ng-packagr": "^11.2.1",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "typescript": "~4.1.5",
    "eslint": "^7.6.0",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-jsdoc": "30.7.6",
    "eslint-plugin-prefer-arrow": "1.2.2",
    "@angular-eslint/builder": "2.1.0",
    "@angular-eslint/eslint-plugin": "2.1.0",
    "@angular-eslint/eslint-plugin-template": "2.1.0",
    "@angular-eslint/schematics": "2.1.0",
    "@angular-eslint/template-parser": "2.1.0",
    "@typescript-eslint/eslint-plugin": "4.16.1",
    "@typescript-eslint/parser": "4.16.1"
  }
}

I just ran into this same error doing the exact same thing.我只是在做同样的事情时遇到了同样的错误。

I noticed I had this in the auto-generated.eslintrc.json file:我注意到我在 auto-generated.eslintrc.json 文件中有这个:

"ignorePatterns": [
  "projects/**/*"
],

If I'm reading that pattern right, it's saying to ignore everything in my projects, so it makes sense now that it couldn't find anything to lint.如果我没看错这个模式,那就是忽略我项目中的所有内容,所以现在它找不到任何要 lint 的东西是有道理的。 I removed this pattern and linting worked.我删除了这种模式并且 linting 有效。

So it looked like this:所以它看起来像这样:

"ignorePatterns": [],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 不确定如何在角度项目中使用 ng lint - Not sure how to use ng lint in angular project 如何在 angular 项目中调试 ng lint broken - How to debug ng lint broken in angular project 使用 ng serve 在 angular 中发生未处理的异常 - An unhandled exception occurred in angular using ng serve angular ng serve 命令抛出错误:发生未处理的异常:项目不存在 - angular ng serve command throws error: An unhandled exception occurred: Project does not exist 无法在我的angular-cli项目上运行ng lint - Can't run ng lint on my angular-cli project Ng 使用 Angular 10 项目时的构建问题 - [发生未处理的异常:作业名称“..getProjectMetadata”不存在。] - Ng Build issues when using Angular 10 project - [An unhandled exception occurred: Job name “..getProjectMetadata” does not exist.] Angular 6 ng lint combineLatest 已弃用 - Angular 6 ng lint combineLatest is deprecated Angular中的ng lint --format = stylish和ng lint有什么区别 - What is difference between `ng lint --format=stylish` and `ng lint` in Angular 在干净的 Angular 项目中运行“ng lint”时,eslint 会为另一个文件夹中完全不同的项目提供错误 - When running "ng lint" in a clean Angular project eslint gives errors for a completely different project in another folder 发生未处理的异常:项目不存在。 Angular SSR - An unhandled exception occurred: Project does not exist. Angular SSR
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM