错误:打字稿任务检测没有为以下配置提供任务

问题描述 投票:2回答:3

我尝试在tasks.json中为typescript类型任务添加一个路径:

{
    "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

并且命令工作正常。

typescript visual-studio-code tsc vscode-tasks
3个回答
2
投票

在我的情况下,问题是因为VSCode没有动态读取tasks.json这一事实。即当我更改tasks.json时,我必须重新启动VSCode。重启后一切正常。 Here is a similar discussion,他们说:

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

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


6
投票

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

我有完全相同的问题,经过一些修补,我通过在路径中用双向后斜线/替换正斜杠\\来解决问题。

例如,替换

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

通过

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

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


0
投票

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

有:

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

变成:

{ ... "tsconfig": "src/project-foo/tsconfig.json" ... }
© www.soinside.com 2019 - 2024. All rights reserved.