How to debug ng lint broken in angular project

Viewed 737

In my angular app, when I run the nglint I got this exception

    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).

1 Answers

Debug in browser

Open Chrome browser(or install it first if you don't have it)

  • 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 will open browser automatically and you will be able to debug your issue just like you would do it in browser.

enter image description here

Debug in 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 should hit that breakpoint and you will be able to debug it.

enter image description here

Related