找不到任务'tsc:build-tsconfig.json'

时间:2019-04-25 09:50:46

标签: visual-studio typescript

enter image description here 您好,我正在关注本教程 https://code.visualstudio.com/docs/typescript/typescript-tutorial 调试打字稿,但遇到了屏幕截图中所示的错误。 如果仍然选择调试,则调试器可以工作,但无法设置任何断点。我怀疑这与无法设置任务文件有关。 有建议吗?

6 个答案:

答案 0 :(得分:1)

我遇到了类似的问题。就我而言,tsconfig.json 文件不在主文件夹中,而是在子文件夹中。就我而言,工作配置如下


{
      "type": "node",
      "request": "launch",
      "name": "Launch server",
      "program": "${workspaceFolder}/server/index.ts",
      "preLaunchTask": "tsc: build - server/tsconfig.json",
      "outFiles": ["${workspaceFolder}/out/**/*.js"]
}

答案 1 :(得分:0)

默认情况下,任务tsc: build - tsconfig.json来自VSCode,它检测到tsconfig.json的存在。根据您的屏幕截图,我可以告诉您您已经有了该文件。因此,如果无法检测到它是很奇怪的。

请确保tsconfig.json的文件内容有效。

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "outDir": "out",
    "sourceMap": true
  }
}

要检查任务是否存在,可以选择菜单终端->运行构建任务,或在MacOS上按 Shift + Command + B 。如果正确,您将看到两个可用的任务,如下图所示。

enter image description here

否则,步骤一定有问题。也许preLaunchTask中有多余的空间。作为参考,我也将我的launch.json复制粘贴到此处。

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${workspaceFolder}/helloworld.ts",
      "preLaunchTask": "tsc: build - tsconfig.json",
      "outFiles": [
        "${workspaceFolder}/out/**/*.js"
      ]
    }
  ]
}

答案 2 :(得分:0)

因为找不到tsconfig文件的路径。 查看您的文件夹结构,该结构是否包含多个具有相同名称的相同文件夹...,因此y调试器很困惑,无法找到路径...文件夹,其中包含tsconfig文件...

答案 3 :(得分:0)

当您使用Ctrl + Shift + B终端时,将冲洗“运行构建任务”。您将在终端中看到

“>执行任务:tsc -p c:....

终端将被任务重用,请按任意键将其关闭。”

然后双击ts文件并按f5键,您必须选择要在哪个c环境下运行ts文件,然后将输出显示在调试控制台中。

答案 4 :(得分:0)

如果扩展主机崩溃了,也会发生这种情况。这样可以防止任务引擎找到请求的任务。通常,您应该在烤面包机中看到一条消息,您可以在其中立即重新启动扩展主机。之后,调试器和任务开始工作。

答案 5 :(得分:0)

对于 Ubuntu Linux 20.04 LTS(但在其他操作系统上很可能是相同的)让 preLaunchTask 为我工作的原因是同时使用本地 tasks.json 和 launch.json

所以我的文件夹结构(预构建)是:

.vscode/launch.json
.vscode/tasks.json
dist
src/index.ts
package.json
tsconfig.json

我的 launch.json 包含:

{
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "TS preLaunchTask-build",
            "program": "${file}",
            "preLaunchTask": "tsc: build",
            "outFiles": ["${workspaceFolder}/dist/**/*.js"],
            "skipFiles": [
                "<node_internals>/**", "node_modules",
              ]
        },
    ]
}

我的 tasks.json 包含:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "command": "echo hello yes working!",
            "problemMatcher": [],
            "label": "myTask"
        },
        {
            "type": "typescript",
            "tsconfig": "tsconfig.json",
            "problemMatcher": ["$tsc"],
            "group": "build",
            "label": "tsc: build"
        },
    ]
}

我的 tsconfig.json 包含:

{
  "compilerOptions": {
      "outDir": "./dist",
      "sourceMap": true,
      "target": "es5",
      "module": "commonjs"
  },
  "include": [
      "src/**/*"
  ]
}

用法:在 index.ts 中,只需按 F5 设置断点

我还包含了另一个任务“myTask”,您可以将 launch.json 中的 preLaunchTask 行更改为:"preLaunchTask": "myTask",(它将向控制台输出一些文本以验证 preLaunchTask 现在正在工作)

这样,如果您仍然有问题,您可以查看问题是在您的 tsconfig 设置中,还是 preTaskLaunch 设置问题。

(我原以为它应该自己解决这个问题,但显然不是在当前撰写本文时 - 但确实强制(对我而言)基于项目而不是全局配置将调试配置提交到 repo 的优势)

相关问题