question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide Angular Build Problem Matcher

See original GitHub issue

I have the following task for build:

{
			"label": "build",
			"type": "npm",
			"script": "build",
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"isBackground": true,
			"problemMatcher": {
				"owner": "typescript",
				"source": "ts",
				"applyTo": "closedDocuments",
				"fileLocation": ["relative", "${workspaceRoot}/src"],
				"pattern": "$tsc",
				"background": {
					"activeOnStart": true,
					"beginsPattern": {
						"regexp": "(.*?)"
					},
					"endsPattern": {
						"regexp": "Compiled |Failed to compile."
					}
				}
			}
		},

This used to show errors/warnings under problems. With the new syntax it doesn’t work and I can’t find any information on how this needs to be fixed to parse errors for angular properly.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:8
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
kvart714commented, Mar 17, 2021

Hello everybody,

I’ve updated Angular to 11 version and have faced with the issue.

The standard typescript problem matcher of VS Code ($tsc) cannot parse ng build errors anymore.

I have reviewed VS Code source code and have found a regular expression which parses errors from tsc (link).

The following regex is used: /^([^\s].*)[\(:](\d+)[,:](\d+)(?:\):\s+|\s+-\s+)(error|warning|info)\s+TS(\d+)\s*:\s*(.*)$/

But Angular displays errors in the following formats now: Error: src/app/app.component.ts:9:18 - error TS1005: ';' expected.

and problem matcher takes the row ‘Error: src/app/app.component.ts’ as a file path with the extra ‘Error: ’ word at the beginning. That causes incorrect file paths building and VS Code failing during attempt to open the file with the error:

1615923619189

I don’t know whom to reach with this issue and this branch is the single one which I’ve found in all angular/angular-cli/vscode repositories, that’s why I’ve written it here.

Moreover, problem matcher $msCompile source code you mentioned is located next to it. But I don’t understand why you even need $msCompile. I use the following matcher as a temporary solution in my tasks.json:

"problemMatcher": [
  {
    "base": "$tsc",
    "pattern": {
      "regexp": "^(Error: )?([^\\s].*)[\\(:](\\d+)[,:](\\d+)(?:\\):\\s+|\\s+-\\s+)(error|warning|info)\\s+TS(\\d+)\\s*:\\s*(.*)$",
      "file": 2,
      "line": 3,
      "column": 4,
      "severity": 5,
      "code": 6,
      "message": 7
    }
  }
],

But it works half the time because the error messages are displayed in different formats.

4reactions
harishrathicommented, Dec 24, 2021

I was getting some error when using @kvart714, so used https://regex101.com/ , pasted all errors and came up with below. This exactly matches with the default $tsc matcher except the beginning Error:

                "pattern": {
                    "regexp": "^Error: ([^\\s].*)[\\(:](\\d+)[,:](\\d+)(?:\\):\\s+|\\s+-\\s+)(error|warning|info)\\s+TS(\\d+)\\s*:\\s*(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "code": 5,
                    "message": 6
                },

current-matcher: https://github.com/microsoft/vscode/blob/149a8b71c534df0554c17b05cf1a925e9139c47f/extensions/typescript-language-features/package.json#L1105

Read more comments on GitHub >

github_iconTop Results From Across the Web

VS Code task problem matcher for Angular CLI build/serve ...
I tried to create a custom matcher, but it looks harder than I expected. Angular CLI outputs typescript errors as well as html...
Read more >
Tasks in Visual Studio Code
VS Code can process the output from a task with a problem matcher. Problem matchers scan the task output text for known warning...
Read more >
Tutorial: Creating custom route matches - Angular
Pattern matching with the Angular Router provides you with a lot of flexibility when you have dynamic URLs in your application. To learn...
Read more >
Debug angular like PRO with visual studio code - Medium
It will launch angular application in debugger mode. In case some one doesn't know way of adding debugger point, it's quite simple just...
Read more >
Angular Material - Error State Matcher for Form Fields (2021)
You can get more in-depth knowledge about Angular Forms & Custom Form Controls in my brand-new advanced course ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found