[英]vscode not compiling typescript file
我发现 vscode 无法编译我的 typescript 代码,即使我完全按照他们的教程进行操作: https://code.visualstudio.com/docs/typescript/typescript-compiling
完成上述教程的所有配置后,当我单击“运行 -> 不调试运行”时,我得到:
无法启动程序“/Users/username/Desktop/work/ts/main.ts”,因为找不到相应的 JavaScript。
但是,如果我运行
tsc
在终端上,然后“运行 - > 运行而不调试”工作。
“main.ts”:
let a : Array<number> = [1,2,3]
let b : number[] = a
console.log(a === b)
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"outDir": "out",
"sourceMap": true,
}
}
发射.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/main.ts",
"outFiles": [
"${workspaceFolder}/**/*.js"
]
}
]
}
任务.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": [
"$tsc"
],
"group": {
"kind": "build",
"isDefault": true
},
"label": "tsc: build - tsconfig.json"
}
]
}
在tasks.json
需要更改label,例如"label": "build"
在launch.json
我们可以使用 preLaunchTask 属性 - "preLaunchTask": "build"
运行调试或不运行应该开始构建并继续观察。 构建任务本身也应该通过Ctrl+Shift+B
工作
发射.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/main.ts",
"preLaunchTask": "build",
"outFiles": [
"${workspaceFolder}/out/**/*.js"
]
}
]
}
任务.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": [
"$tsc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
你也可能想排除一些目录
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"outDir": "out",
"sourceMap": true,
},
"exclude": ["**/node_modules/*", "out", "coverage"]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.