属性 vscode 中的 launch.json 中不允许使用参数

Property args is not allowed in launch.json in vscode

我只是想向 vscode 中的 launch.json 文件添加一些基本配置,但出现错误,因为 属性 args is not allowed . 下面是我的配置。

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "attach",
            "name": "index",         
            "args": [
                "src/index.ts"
            ],
            "cwd": "${workspaceFolder}"           
        }
    ],
    "compounds": []
}

那是个愚蠢的错误。据此 doc

VS Code debuggers typically support launching a program in debug mode or attaching to an already running program in debug mode. Depending on the request (attach or launch) different attributes are required and VS Code's launch.json validation and suggestions should help with that.

因此,当我将请求从 attach 更改为 launch 时,一切都很完美。只有请求类型launch支持配置args.

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "index",         
            "args": [
                "src/index.ts"
            ],
            "cwd": "${workspaceFolder}"           
        }
    ],
    "compounds": []
}