在我的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"
}
]
}
答案 0 :(得分:1)
如果设置"preLaunchTask": "npm: build"
,则VS代码会在工作区根目录(包含build
文件夹的目录package.json
中使用npm脚本.vscode
。它不想在.vscode\tasks.json
中执行构建任务。
这也是导致错误的原因-package.json
位于apiEngine
文件夹中更深一层,因此VS Code无法在工作区根目录中找到脚本。
要改为调用IDE任务,可以为构建任务指定label
并在npm: build
中设置此标签而不是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",
...