2

I am trying to configure vscode to compile typescript by looking in to this question Visual Studio Code: compile typescript module and this article https://cmatskas.com/typescript-and-vs-code/ but getting an error. Need help.

My project tree:

enter image description here

The file server.ts it is what I want to compile but later I will have more .ts files.

Here is my 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": "always",

    "windows": {
        "command": "tsc"
    },

    // args is the HelloWorld program to compile.
    "args": ["-p", "."],

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

and my tsconfig.json

{ "compilerOptions": { "target": "ES5", "module": "commonjs", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": false, "noImplicitAny": false, "sourceRoot": "/" }, "exclude": [ "node_modules" ] }

my tsc version: message TS6029: Version 1.7.5

Detailed error:

C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:31084 var jsonOptions = json["compilerOptions"]; ^ TypeError: Cannot read property 'compilerOptions' of undefined at getCompilerOptions (C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:31084:35) at Object.parseJsonConfigFileContent (C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:31074:22) at parseConfigFile (C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:31351:40) at performCompilation (C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:31362:45) at Object.executeCommandLine (C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:31336:9) at Object.<anonymous> (C:\Users\User\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:31635:4) at Module._compile (module.js:435:26) at Object.Module._extensions..js (module.js:442:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:311:12)

Community
  • 1
  • 1
Sergino
  • 10,128
  • 30
  • 98
  • 159

1 Answers1

3

When Visual Studio code runs the typescript compiler, it runs relative to the root folder but your tsconfig.json is actually in the ./server folder. This is why the compiler is not able to locate your tsconfig.json file in the root. All you need to do is that in your tasks.json, you would need to update the args parameter to look as below, assuming your entire project is in the server folder. i.e you don't have any .ts files in the client folder that needs to be compiled by typescript compiler.

// args is the HelloWorld program to compile.
"args": ["-p", "./server"],

If your client folder also has ts files that needs to be compiled, then you would need to move the tsconfig.json to the root folder and the typescript compiler will be able to find it.