Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct tasks.json config for compiling typescript in Visual Studio Code?

Using Ctrl+Shift+B I added a default tasks.json file and uncommented the second task runner block. I have a typescript file in the root of the directory and a tsconfig.json.

Everytime I compile I get 'error TS5023: Unknown compiler option 'p'. What is the correct definition to allow me to compile a typescript file? Can all files be compiled in one go even if they are in subdirectories?

I have tried changing the args below to ["${file}"] which simply allows me to compile the file that is open. This works. I've also run the tsc command from the command prompt and no -p or -project arguments exists.

tasks.json

{
    "version": "0.1.0",

    // The command is tsc. Assumes that tsc has been installed using npm install -g typescript
    "command": "tsc",

    // The command is a shell script
    "isShellCommand": true,

    // Show the output window only if unrecognized errors occur. 
    "showOutput": "silent",

    // Tell the tsc compiler to use the tsconfig.json from the open folder.
    "args": ["-p", "."],

    // use the standard tsc problem matcher to find compile problems
    // in the output.
    "problemMatcher": "$tsc"
}

tsconfig.json

{
    "compilerOptions": {
        "target": "ES5",
        "module": "amd",
        "sourceMap": true
    }
}

VS Code: v0.30

TypeScript: v1.4

like image 987
Naeem Sarfraz Avatar asked Dec 02 '25 23:12

Naeem Sarfraz


2 Answers

I had the same problem. It was a wrong PATH variable to the TypeScript compiler. (try to type tsc -v in a command window). The tsconfig.json is supported in TypeScript version 1.5. My PATH variable was set to version 1. When I changed the system PATH variable to the updated installation folder (C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.5) and a restart of Visual Studio Code, everything was fine. (Remove all entries from the args!) Like:

{
    "version": "0.1.0",

    // The command is tsc. Assumes that tsc has been installed using npm install -g typescript
    "command": "tsc",

    // The command is a shell script
    "isShellCommand": true,

    // Show the output window only if unrecognized errors occur. 
    "showOutput": "always",

    // Tell the tsc compiler to use the tsconfig.json from the open folder.
    "args": [],

    // use the standard tsc problem matcher to find compile problems
    // in the output.
    "problemMatcher": "$tsc"
}
like image 123
Stephan Mendler Avatar answered Dec 04 '25 13:12

Stephan Mendler


I struggled until I understood how npm was installing the typescript 1.5 beta (or not) on my windows laptop.

The key to getting this to work for me was:

  1. uninstall current version of typescript (for me, this was version 1.4.1)

    npm uninstall -g typescript

  2. install 1.5.1-beta version

    npm install -g [email protected]
    (npm will print an error message & list all versions if you use an incorrect version)

  3. Locate the tsc.cmd file - created under the npm folder. On my Windows 8.1 machine, this was stored at: C:\Users\Bob.Chiverton\AppData\Roaming\npm\tsc.cmd

  4. Add this to the tasks.json file: "command": "C:\Users\Bob.Chiverton\AppData\Roaming\npm\tsc.cmd",

Now re-try ctrl-Shift-B.

-bob

like image 44
Bob Chiverton Avatar answered Dec 04 '25 13:12

Bob Chiverton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!