简体   繁体   English

如何在 angular 项目中调试 ng lint broken

[英]How to debug ng lint broken in angular project

In my angular app, when I run the nglint I got this exception在我的 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)

Do someone know how to debug this.有人知道如何调试它吗? Is there a way I can debug it like we do code (c#, javascript).有没有一种方法可以像我们编写代码(c#、javascript)一样调试它。

Debug in browser在浏览器中调试

Open Chrome browser(or install it first if you don't have it)打开Chrome浏览器(没有的话先安装)

  • Install Node Inspector Manager extension安装Node Inspector Manager扩展

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

  • Open console in your app and type在您的应用程序中打开控制台并输入

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

Chrome will open browser automatically and you will be able to debug your issue just like you would do it in browser. Chrome 将自动打开浏览器,您将能够像在浏览器中一样调试您的问题。

在此处输入图像描述

Debug in VS Code在 VS 代码中调试

  • open(or create first) launch.json file打开(或先创建) launch.json文件

  • 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 go 到node_modules\tslint\lib\rules\maxLineLengthRule.js:51:72并在那里放置断点

  • run Debug lint configuration运行调试 lint 配置

VS code should hit that breakpoint and you will be able to debug it. VS 代码应该命中该断点,您将能够对其进行调试。

在此处输入图像描述

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM