2

我尝试在 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.jsonand src/client/tsconfig.json。我也在控制台中输入它:

tsc -p src/client/tsconfig.json

并且命令工作正常。

4

3 回答 3

7

在我的情况下,问题是由于 VSCode 没有即时读取 tasks.json 引起的。即当我更改tasks.json 时我必须重新启动VSCode。重启后一切正常。这是一个类似的讨论,他们说:

如果之前没有启动任务,那么在更改后没有重新解析 tasks.json 存在问题。这是为下一个版本修复的。然而看起来人们即使没有编辑tasks.json也能得到这个。

该评论是在 2017 年添加的,但看起来重启的问题还没有解决(我有 VSCode 1.32.1)。

于 2019-03-11T17:59:14.510 回答
6

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

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

例如,更换

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

经过

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

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

于 2018-04-26T13:09:48.860 回答
0

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

有:

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

变成:

{ ... "tsconfig": "src/project-foo/tsconfig.json" ... }
于 2019-06-24T18:04:17.670 回答