[英]how to debug a typescript node application in vscode error
在我的vscode应用程序中,我有一个名为apiEngine /的文件夹。
在此文件夹中是我的节点应用程序。
为什么不在vscode中调试?
.vscode \\ launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Build Project",
"program": "${workspaceFolder}\\apiEngine\\src\\index.ts",
"preLaunchTask": "npm: build",
"sourceMaps": true,
"smartStep": true,
"internalConsoleOptions": "openOnSessionStart",
"outFiles": [
"${workspaceFolder}/apiEngine/dist/**/*.js"
]
}
]
}
.vscode \\ tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "build",
"path": "apiEngine/",
"group": "build",
"problemMatcher": []
},
{
"type": "typescript",
"tsconfig": "apiEngine/tsconfig.json",
"problemMatcher": [
"$tsc"
],
"group": "build"
}
]
}
如果设置"preLaunchTask": "npm: build"
,则VS代码期望在工作区根目录(包含.vscode
文件夹的目录)的package.json
中build
一个npm脚本。 它不想在.vscode\\tasks.json
执行构建任务。
这也是原因,为什么你的错误- package.json
位于更深一层内apiEngine
文件夹,所以VS代码无法找到工作区根里面的脚本。
为了调用IDE任务,您可以为构建任务指定label
并设置该标签,而不是npm: build
in preLaunchTask
。 任务的path
参数将提供正确的package.json
位置。
.vscode \\ tasks.json:
tasks: [
{
label: "npm-build",
type: "npm",
script: "build",
path: "apiEngine/",
group: "build",
problemMatcher: []
},
...
];
.vscode \\ launch.json:
...
// before:
// "preLaunchTask": "npm: build"
// after:
"preLaunchTask": "npm-build",
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.