vscode not compiling typescript file

derek

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"
        }
    ]
}
Radik

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Compiling a cpp file with vscode, in Ubuntu

From Dev

Optimize compiling of large TypeScript file

From Dev

Typescript: Empty output file when compiling

From Dev

Only lint typescript when saving file in VSCode

From Dev

TypeScript error inside JavaScript file in VSCode

From Dev

Testing a file's contents in VSCode TypeScript

From Dev

How to make typescript compiler to print list of file names it is compiling?

From Dev

Adding typescript import prevents compiling to a single js file

From Dev

TypeScript is compiling into this failing JS file when importing a module. Why?

From Dev

Does type checking occur after compiling typescript file?

From Dev

How can I use a custom tslint rule written in TypeScript with vscode-tslint without compiling to JS?

From Dev

typescript compiling (in terms of Java compiling)

From Dev

Enable -Xlint for VSCode Java Compiling

From Dev

Compiling Java into application in VSCode on Mac

From Dev

How to block vscode typescript file importing from a folder it should not?

From Dev

Using a different .eslintrc config file for typescript and javascript in VSCode?

From Dev

Typescript Cloud function not compiling

From Dev

TypeScript - Compiling to single files

From Dev

Run Nodemon with Typescript compiling?

From Dev

TypeScript conditional types not compiling

From Dev

TypeScript error compiling Map

From Dev

Typescript not compiling enums to numbers

From Dev

TypeScript: Imported Module Not Compiling

From Dev

Compiling Code in TypeScript

From Dev

Compiling a typescript project with webpack

From Dev

Typescript Cannot write file would overwrite input file. Error when compiling Ionic 3 app

From Dev

Is there a way to avoid adding (///<reference path="..."/>) when compiling to single '*.js' file with TypeScript 1.8 compiler

From Dev

Error while compiling C program with gcc in VSCode

From Dev

Compiling C# projects with VSCode on Ubuntu

Related Related

  1. 1

    Compiling a cpp file with vscode, in Ubuntu

  2. 2

    Optimize compiling of large TypeScript file

  3. 3

    Typescript: Empty output file when compiling

  4. 4

    Only lint typescript when saving file in VSCode

  5. 5

    TypeScript error inside JavaScript file in VSCode

  6. 6

    Testing a file's contents in VSCode TypeScript

  7. 7

    How to make typescript compiler to print list of file names it is compiling?

  8. 8

    Adding typescript import prevents compiling to a single js file

  9. 9

    TypeScript is compiling into this failing JS file when importing a module. Why?

  10. 10

    Does type checking occur after compiling typescript file?

  11. 11

    How can I use a custom tslint rule written in TypeScript with vscode-tslint without compiling to JS?

  12. 12

    typescript compiling (in terms of Java compiling)

  13. 13

    Enable -Xlint for VSCode Java Compiling

  14. 14

    Compiling Java into application in VSCode on Mac

  15. 15

    How to block vscode typescript file importing from a folder it should not?

  16. 16

    Using a different .eslintrc config file for typescript and javascript in VSCode?

  17. 17

    Typescript Cloud function not compiling

  18. 18

    TypeScript - Compiling to single files

  19. 19

    Run Nodemon with Typescript compiling?

  20. 20

    TypeScript conditional types not compiling

  21. 21

    TypeScript error compiling Map

  22. 22

    Typescript not compiling enums to numbers

  23. 23

    TypeScript: Imported Module Not Compiling

  24. 24

    Compiling Code in TypeScript

  25. 25

    Compiling a typescript project with webpack

  26. 26

    Typescript Cannot write file would overwrite input file. Error when compiling Ionic 3 app

  27. 27

    Is there a way to avoid adding (///<reference path="..."/>) when compiling to single '*.js' file with TypeScript 1.8 compiler

  28. 28

    Error while compiling C program with gcc in VSCode

  29. 29

    Compiling C# projects with VSCode on Ubuntu

HotTag

Archive