How to fix incorrect path in vscode problem matcher when compiling with $tsc-watch

922 Views Asked by At
  • My project workspace folder is located at D:\salix\fantasy.
  • My TypeScript configuration file is located at D:\salix\fantasy\tsconfig.json

No matter what I do, I can't seem to get the problem matcher for my project to resolve to the correct location. For some reason the TypeScript compiler is reporting the full path, relative to the drive root, for each error it encounters, and vscode is attempting to treat those paths as relative to the workspace folder. As such, I can't click on a problem without getting "file not found", because the error paths are being reported like this:

Error path resolving incorrectly

Here is my tsconfig.json file, which is in the workspace root, as standard:

{
  "compilerOptions": {
    "module": "ESNext",
    "target": "ESNext",
    "strictNullChecks": true,
    "exactOptionalPropertyTypes": true,
    "sourceMap": true,
    "moduleResolution": "Node",
    "removeComments": true,
    "outDir": "dist",
  },
  "include": [
    "source/**/*.ts",
  ],
  "exclude": [
    "node_modules",
    "**/node_modules/*",
    "source/shared/libraries/*",
  ]
}

Here is my tasks.json file:

{
    "version": "2.0.0",
    "tasks": [
    {
      "label": "Server",
      "type": "typescript",
      "tsconfig": "tsconfig.json",
      "option": "watch",
      "problemMatcher": "$tsc-watch",
      "group": {
        "kind": "build",
        "isDefault": true
      },
    }
  ]
}
  • I have tried every variation of the "cwd" option that I can think of, to no avail.
  • I have tried changing the "problemMatcher" configuration to use "fileLocation": "absolute" and "fileLocation": "relative", and neither of these solved the problem.
  • I have tried manually specifying different options for root and source paths in tsconfig.json, and no matter what I do, TypeScript always reports errors like so (taken from the terminal in vscode):
salix/fantasy/source/client/dom/h.dynamic.ts:66:44 - error TS2345: Argument of type '{ data: (writer: Writer<any, any>) => Lens<any, any>; changes: Stream<unknown[]>; invalidations: Stream<unknown[]>; sync(origin: TimelineOrigin, dtime: number, dpos: number, client: CursorClient<...>): JobInterface; }' is not assignable to parameter of type 'ConnectionDriver<any>'.

How do I get vscode and the TypeScript compiler to agree on where the root path is, or to just get the Typescript compiler to stop including salix/fantasy/ in the path it reports for each error?

EDIT:

I tested manual compilation from the command line, and TypeScript is reporting the paths correctly, which means that for some reason vscode is giving the TypeScript compiler the wrong root path. As a workaround, I have changed my task configuration to the following:

{
    "version": "2.0.0",
    "tasks": [
    {
      "label": "Server",
      "type": "shell",
      "problemMatcher": "$tsc-watch",
      "command": "cd ${workspaceFolder}; tsc -w",
      "isBackground": true,
      "options": {
        "cwd": "${workspaceFolder}"
      },
      "group": {
        "kind": "build",
        "isDefault": true
      },
    }
  ]
}

This works, but I'd still really like to know why I can't get the standard "typescript" task type to use the correct file location.

1

There are 1 best solutions below

0
On

I solved this issue configuring the Problem Matcher with the correct file location. My configuration is a bit different, but the concept still applies. You could check and see if it does work for you too.

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "tsc",
            "type": "shell",
            "command": "npx",
            "args": ["tsc", "--noEmit"],
            "presentation": {
                "reveal": "never",
                "echo": false,
                "focus": false,
                "panel": "dedicated"
            },
            "problemMatcher": {
                "base": "$tsc-watch",
                "fileLocation": ["relative", "${workspaceFolder}/../MY_PROJECT_DIR"],
            },
        },
    ],
}