Error: The typescript task detection didn't contribute a task for the following configuration

Error: The typescript task detection didn't contribute a task for the following configuration

我尝试在 tasks.json 中为打字稿类型任务添加路径:

{
    "version": "2.0.0",
    "tasks": [
        {   
            "identifier": "tsc-client", 
            "label": "tsc-client", 
            "type": "typescript",
            "tsconfig": "src/client/tsconfig.json",
            "problemMatcher": [
                "$tsc"
            ]
        },
        {   
            "identifier": "tsc-server", 
            "label": "tsc-server", 
            "type": "typescript",
            "tsconfig": "src/server/tsconfig.json",
            "problemMatcher": [
                "$tsc"
            ]
        },
        {
            "identifier": "build-all",
            "label": "build-all",
            "dependsOn": ["tsc-client", "tsc-server"]
        }
    ]
}

然后在我的 launch.json 我有:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "preLaunchTask": "tsc-client",
            "name": "Launch Program",
            "program": "${workspaceFolder}/server/server-repsic.js"
        }
    ]
}

我打开它并获得:

Error: The typescript task detection didn't contribute a task for the following configuration:
{
    "identifier": "tsc-server",
    "label": "tsc-server",
    "type": "typescript",
    "tsconfig": "src/server/tsconfig.json",
    "problemMatcher": [
        "$tsc"
    ]
}
The task will be ignored.

我检查了根路径中是否有 src/server/tsconfig.jsonsrc/client/tsconfig.json。我也在控制台中输入:

tsc -p src/client/tsconfig.json

命令运行正常。

我在这里可能有点晚了,但这可能会对其他人有所帮助。

我遇到了完全相同的问题,经过一番修改后,我通过在路径中用双反斜杠 \ 替换正斜杠 / 解决了这个问题。

例如,替换

"tsconfig": "src/server/tsconfig.json",

来自

"tsconfig": "src\server\tsconfig.json",

免责声明:我只在 Windows 上测试过。考虑到正斜杠是所有其他平台的标准,这可能不适用于其他平台 :/.

在我的例子中,问题是由于 VSCode 没有即时读取 tasks.json 而引起的。 IE。当我更改 tasks.json 时,我必须重新启动 VSCode。重启后一切正常。 Here is a similar discussion,他们说:

There was a problem that the tasks.json didn't get reparsed after a change if not task has been started before. This is fixed for the next releases. However looks like that people get this even without editing the tasks.json.

该评论是在 2017 年添加的,但重启问题似乎尚未解决(我有 VSCode 1.32.1)。

我刚刚遇到了@Benjamin Blois 上面报告的相反问题,tasks.json 中打字稿任务路径中的所有反斜杠现在都必须用正斜杠替换。对我来说很好,这样更易​​读,不需要转义等。

有:

{ ... "tsconfig": "src\project-foo\tsconfig.json" ... }

更改为:

{ ... "tsconfig": "src/project-foo/tsconfig.json" ... }