Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find the task 'tsc: build - tsconfig.json'

enter image description here Hello I am following this tutorial https://code.visualstudio.com/docs/typescript/typescript-tutorial to debug typescript but I have encountered error as shown in the screenshot. If I choose debug anyway, the debugger works but I cant set any breakpoint. I suspect it has something to do with failing to set up the task file. Any advise guys?

like image 268
tnkh Avatar asked Apr 25 '19 09:04

tnkh


4 Answers

Task tsc: build - tsconfig.json by default comes from VSCode when it detects the existence of tsconfig.json. Based on your screenshot, I can tell that you already have the file. So, it is odd if it can't be detected.

Please make sure the file content of tsconfig.json is valid.

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "outDir": "out",
    "sourceMap": true
  }
}

Also to check whether the tasks are exist, you can choose menu Terminal -> Run Build Task or press Shift + Command + B on MacOS. If correct, you can see two tasks available there as the image below.

enter image description here

Otherwise, there must be something wrong with the steps. Perhaps, there is an extra space in preLaunchTask. For reference, I also copy paste my launch.json here.

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${workspaceFolder}/helloworld.ts",
      "preLaunchTask": "tsc: build - tsconfig.json",
      "outFiles": [
        "${workspaceFolder}/out/**/*.js"
      ]
    }
  ]
}
like image 85
deerawan Avatar answered Oct 03 '22 14:10

deerawan


For other language users, the tsc: build command maybe be another command, such as tsc: 构建 in Chinese.

my launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "pwa-node",
      "request": "launch",
      "name": "Launch Program",
      "skipFiles": [
        "<node_internals>/**"
      ],
      "program": "${workspaceFolder}/index.ts",
      "preLaunchTask": "tsc: 构建 - tsconfig.json",
      "outFiles": [
        "${workspaceFolder}/out/**/*.js"
      ]
    }
  ]
}
like image 38
KnownRock J Avatar answered Oct 03 '22 16:10

KnownRock J


I had a similar problem. In my case, the tsconfig.json file was not in the main folder, but in a subfolder. In my case, the working configuration looked like this


{
      "type": "node",
      "request": "launch",
      "name": "Launch server",
      "program": "${workspaceFolder}/server/index.ts",
      "preLaunchTask": "tsc: build - server/tsconfig.json",
      "outFiles": ["${workspaceFolder}/out/**/*.js"]
}
like image 31
Alexandr Zverg Avatar answered Oct 03 '22 16:10

Alexandr Zverg


When you Ctrl+Shift+B terminal will run Run Build Task.. You'll see in the terminal

">Executing task: tsc -p c:....

Terminal will be reused by tasks, press any key to close it."

Then after that double click a ts file and press F5 you will have to select at which environment do you want your ts file to run and then you will see the output in the debug console.

like image 22
Ronald Abellano Avatar answered Oct 03 '22 16:10

Ronald Abellano