I found vscode failed to compile my typescript code even I followed exactly their tutorial: https://code.visualstudio.com/docs/typescript/typescript-compiling
After all the configurations of the above tutorial, when I click "Run -> Run without Debugging", I got:
Cannot launch program '/Users/username/Desktop/work/ts/main.ts' because corresponding JavaScript cannot be found.
However, if I run
tsc
on terminal, then "Run -> Run without Debugging" works.
"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,
}
}
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/main.ts",
"outFiles": [
"${workspaceFolder}/**/*.js"
]
}
]
}
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": [
"$tsc"
],
"group": {
"kind": "build",
"isDefault": true
},
"label": "tsc: build - tsconfig.json"
}
]
}
In tasks.json
need to change label, in example "label": "build"
In launch.json
we can use preLaunchTask property - "preLaunchTask": "build"
Run with debug or without it should start build and stay watching. Build task itself should also work by Ctrl+Shift+B
launch.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"
]
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": [
"$tsc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
also you may want to exclude some directories
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"outDir": "out",
"sourceMap": true,
},
"exclude": ["**/node_modules/*", "out", "coverage"]
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments