tnkh
tnkh

Reputation: 1829

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?

Upvotes: 24

Views: 28144

Answers (14)

xaphod
xaphod

Reputation: 6804

It was the capitalization that made your error - the tutorial says

"tsc: Build - tsconfig.json"

.. the correct value is:

"tsc: build - tsconfig.json"

Upvotes: 0

Byron2017
Byron2017

Reputation: 1003

The problem is related to Windows and Unix systems use different conventions for the file separator ("\" in Windows, "/" in Unix, ). With "preLaunchTask": "tsc: build - tsconfig.json", :

  • if you are using VSC with a terminal configured for git bash the real command is going to be: tsc -p /c/aaaa/xxx/...../zzzz/tsconfig.json
  • if you are using VSC with a terminal configured for powerShell the real command is going to be: tsc -p c:\aaaa\xxx\.....\zzzz\tsconfig.json

WORK AROUND:

  • Create a script into "package.json": "debug_build":"tsc",
  • Change "preLaunchTask" to "preLaunchTask": "npm: debug_build",

Upvotes: 0

Alec
Alec

Reputation: 2752

This happened to me after following instructions to set up the Vue.js Volar plugin in takeover mode, which involves disabling built-in TypeScript features.

I fixed by searching extensions for @builtin typescript and re-enabling "TypeScript and JavaScript Language Features".

Upvotes: 0

Charlie Pelayes
Charlie Pelayes

Reputation: 1

I solved it by creating a file tasks.json in folder .vscode with the next code:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "tsc: build - tsconfig.json",
            "type": "shell",
            "command": "tsc",
            "args": ["-p", "tsconfig.json"],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": ["$tsc"]
        }
    ]
}

tasks.json file with the aforementioned code content

Upvotes: 0

JPR
JPR

Reputation: 1

In my case I was able to fix it by adding a build script in the package.json

"scripts": { "build": "tsc --build"

and then from the launch.json I replaced tsc:build for npm: build.

Upvotes: 0

TeaDrinker
TeaDrinker

Reputation: 475

Create launch.json inside .vscode in your workspace and set in there, instead of using vscode user profile settings. I don't know why :(

Upvotes: 0

Anser Waseem
Anser Waseem

Reputation: 37

Be sure to check the exact structure/spelling of Task by pressing Ctrl+Shift+B (on Windows) and Cmd+Shift+B(on Mac). preLaunchTask

In my case, it was tsc: build - projectName/tsconfig.json

Upvotes: 0

KnownRock J
KnownRock J

Reputation: 136

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"
      ]
    }
  ]
}

Upvotes: 2

Leigh Mathieson
Leigh Mathieson

Reputation: 2018

For Ubuntu Linux 20.04 LTS (but may well be the same on other OS's) what got preLaunchTask working for me, was using both a local tasks.json and launch.json

So my folder structure (pre-build) is:

.vscode/launch.json
.vscode/tasks.json
dist
src/index.ts
package.json
tsconfig.json

My launch.json contains:

{
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "TS preLaunchTask-build",
            "program": "${file}",
            "preLaunchTask": "tsc: build",
            "outFiles": ["${workspaceFolder}/dist/**/*.js"],
            "skipFiles": [
                "<node_internals>/**", "node_modules",
              ]
        },
    ]
}

My tasks.json contains:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "command": "echo hello yes working!",
            "problemMatcher": [],
            "label": "myTask"
        },
        {
            "type": "typescript",
            "tsconfig": "tsconfig.json",
            "problemMatcher": ["$tsc"],
            "group": "build",
            "label": "tsc: build"
        },
    ]
}

And my tsconfig.json contains:

{
  "compilerOptions": {
      "outDir": "./dist",
      "sourceMap": true,
      "target": "es5",
      "module": "commonjs"
  },
  "include": [
      "src/**/*"
  ]
}

Usage: whilst within the index.ts just hit F5 with a breakpoint set

I have also included another task, "myTask" you can change the preLaunchTask line in your launch.json to: "preLaunchTask": "myTask", (where it will output some text to console to verify preLaunchTask is now working)

That way, if you still have issues, you can see if the issue is in your tsconfig setup, or if it's a preTaskLaunch setup issue.

(I would have thought it should have resolved this itself, but apparently not at the current time of writing anyway - but does force the advantage (for me) of committing debug config to the repo on project basis rather than global config)

Upvotes: 1

Alexandr Zverg
Alexandr Zverg

Reputation: 81

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"]
}

Upvotes: 8

Ronald Abellano
Ronald Abellano

Reputation: 864

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.

Upvotes: 1

Joerg Krause
Joerg Krause

Reputation: 2179

This happens also if the Extension Host crashed. This prevents the task engine from finding the requested task. Usually, you should see a message in the toaster where you can immediately restart the Extension Host. After that the debugger and tasks work.

Upvotes: 0

Muhammed Ibrahim
Muhammed Ibrahim

Reputation: 13

because it does not find path of tsconfig file.... see your folder structure whether the structure contains multiple same folder with same name...so y debugger confused to find path....so make sure the devlopement folder which you work on has proper path with unique name no same name with its parent folder and contains tsconfig files...

Upvotes: 0

deerawan
deerawan

Reputation: 8443

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"
      ]
    }
  ]
}

Upvotes: 8

Related Questions