如何在 Angular 项目中调试 ng lint 错误

4
在我的Angular应用中,当我运行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)。

1个回答

5

浏览器中的调试

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

  • Install Node Inspector Manager extension

  • Go to node_modules\tslint\lib\rules\maxLineLengthRule.js:51:72 and add line before with debugger;

  • Open console in your app and type

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

Chrome将自动打开浏览器,您将能够像在浏览器中一样调试问题。

在这里输入图片描述

在VS Code中进行调试

  • open(or create first) launch.json file

  • add the following configuration:

    {
      "type": "node",
      "request": "launch",
      "name": "Debug lint",
      "program": "${workspaceFolder}\\node_modules\\@angular\\cli\\bin\\ng",
      "cwd": "${workspaceFolder}",
      "args": ["lint"],
      "console": "integratedTerminal"
    }
    
  • go to node_modules\tslint\lib\rules\maxLineLengthRule.js:51:72 and put breakpoint there

  • run Debug lint configuration

VS Code应该能够触发断点,进而调试代码。

输入图像描述


谢谢你的回答,当我放置调试器并运行命令时,它没有打开 Chrome 实例。我使用的是 Chrome Enterprise 版本。这个问题是否有解决办法,也许我们可以在 VS Code 中进行调试(如果某些安全设置允许的话)。 - Anirudha Gupta
你安装并启用了NIM扩展吗? - yurzui
我已经搞定了,我只是重新启动了Chrome,现在看起来可以工作了。谢谢。我现在是从VS Code尝试它。之前我是从命令提示符中尝试的。 - Anirudha Gupta

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接