如何调试Angular项目中损坏的ng Lint

问题描述

在我的有角度的应用程序中,当我运行nglint时,出现了此异常

    Cannot read property 'check-regex' of undefined

[error] TypeError: Cannot read property 'check-regex' of undefined

    at Rule.getRuleOptions (node_modules\tslint\lib\rules\maxLineLengthRule.js:51:72)
    at Rule.isEnabled (node_modules\tslint\lib\rules\maxLineLengthRule.js:39:26)
    at Object.loadRules (node_modules\tslint\lib\ruleLoader.js:48:22)
    at Linter.getEnabledRules (node_modules\tslint\lib\linter.js:232:29)
    at Linter.lint (node_modules\tslint\lib\linter.js:107:33)
    at _lint (node_modules\@angular-devkit\build-angular\src\tslint\index.js:146:20)
    at async _run (node_modules\@angular-devkit\build-angular\src\tslint\index.js:60:29)

有人知道如何调试它。有没有办法像我们做代码一样调试它(C#,JavaScript)。

解决方法

在浏览器中调试

打开Chrome浏览器(如果没有,请先安装)

  • 安装Node Inspector Manager扩展名

  • 转到node_modules\tslint\lib\rules\maxLineLengthRule.js:51:72并在debugger;之前添加一行

  • 在您的应用中打开控制台,然后输入

    node --inspect ./node_modules/@angular/cli/bin/ng lint
    

Chrome会自动打开浏览器,您可以像在浏览器中一样调试问题。

enter image description here

使用VS代码调试

  • 打开(或先创建)launch.json文件

  • 添加以下配置:

    {
      "type": "node","request": "launch","name": "Debug lint","program": "${workspaceFolder}\\node_modules\\@angular\\cli\\bin\\ng","cwd": "${workspaceFolder}","args": ["lint"],"console": "integratedTerminal"
    }
    
  • 转到node_modules\tslint\lib\rules\maxLineLengthRule.js:51:72并在其中放置断点

  • 运行Debug lint配置

VS代码应达到该断点,您将能够对其进行调试。

enter image description here