VS Code tasks cannot be found by launch config when they are located in workspace config

Viewed 508

In tradition, we put launch.json and tasks.json in .vscode folder in order to make debugger works. Meanwhile, VS Code also support developer to put these 2 configurations into workspace by setting them in *.vscode-workspace. Here are the steps to reproduce:

  1. Create new js project by npm init with all default parameters.
  2. Create new index.js with 1 line of code: console.log('done');
  3. Create new ts-sample.code-workspace file within the same root folder, the content should be like following:
{
    "launch": {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "node",
                "request": "launch",
                "name": "Launch Program",
                "skipFiles": [
                    "<node_internals>/**"
                ],
                "program": "${workspaceFolder}/index.js",
                "preLaunchTask": "nodeversion"
            }
        ]
    },
    "tasks": {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "nodeversion",
                "type": "npm",
                "script": "nodeversion",
            }
        ]
    },
    "folders": [
        {
            "path": "."
        }
    ]
}
  1. Open the workspace
  2. Open index.js and press F5
  3. Error dialog prompted our with the following error message: Could not find the task 'nodeversion'
  4. Open OUTPUT Panel and Error message is shown as following:
Error: The npm task detection didn't contribute a task for the following configuration:
{
    "label": "nodeversion",
    "type": "npm",
    "script": "nodeversion"
}
The task will be ignored.

For easy demo please clone the sample project from https://github.com/mannok/WorkspaceLaunchTaskDemo

Is this a bug of VS Code or something I have missed?

0 Answers
Related