title: Visual Studio Code: compile typescript module
body: <p>I've just downloaded the new Visual Studio Code and my first impression is very positive. For typescript, intellisense works beautifully.</p>
  
  <p>However, there is a strange problem: VS Code doesn't seem to be able to compile typescript modules.</p>
  
  <p>This code:</p>
  
  <pre><code>/// &lt;reference path="../definitions/react.d.ts"/&gt;
  
  import React = require("react");
  </code></pre>
  
  <p>compiles perfectly fine on the cmd, with</p>
  
  <blockquote>
    <p>tsc --module commonjs main.ts</p>
  </blockquote>
  
  <p>but within VS Code, the second line is highlighted in red and the editor complains:</p>
  
  <blockquote>
    <p>cannot compile external modules unless the "-module" flag is provided</p>
  </blockquote>
  
  <p>Of course any typescript code which makes use of modules has to be compiled with this flag. But if the IDE is aware of the usage of modules, why doesn't it set the flag ? Typescript code without modules is compiled on save, without problems.</p>
  
  <p>I think I'm missing some compiler-setup config file. Is there such a thing ? Where can I find it ?</p>
  
  <h2>UPDATE</h2>
  
  <p>I've added the tsconfig.json file:</p>
  
  <pre><code>{
      "compilerOptions": {
          "target": "ES5",
          "module": "commonjs",
          "sourceMap": true
      }
  }
  </code></pre>
  
  <p>This actually removes the error. Unfortunately the IDE no longer compiles my code. At first I thought the config.json would only silence the error message, but it does more than that. Intellisense now works in the sample file. If I type <code>React</code> the autocompletion is triggered and apparently knows React because meaningful suggestions are displayed.</p>
  
  <p>Now, why doesn't VS Code compile the file to js ? I've tried to configure the task runner to do that job, but it doesn't seem to work:</p>
  
  <pre><code>{
      "version": "0.1.0",
  
      // The command is tsc.
      "command": "tsc",
  
      // Show the output window only if unrecognized errors occur. 
      "showOutput": "silent",
  
      // Under windows use tsc.exe. This ensures we don't need a shell.
      "windows": {
          "command": "tsc.exe"
      },
  
      // args is the HelloWorld program to compile.
      "args": ["--module commonjs","${file}"],
  
      // use the standard tsc problem matcher to find compile problems
      // in the output.
      "problemMatcher": "$tsc"
  }
  </code></pre>
  
  <p>If I save the file, nothing happens, even if I explicitly run the build task, there's no response. The name of the task I edited is "tsc", I tried to run that, too. No effect. Then I changed the arguments to <code>"args": ["--module commonjs","main.ts"]</code>, No response.</p>
  
  <h2>UPDATE</h2>
  
  <p>The only way the task runner seems to work is with these two settings:</p>
  
  <blockquote>
  <pre><code>"args": ["${file}"], 
  "isShellCommand": true, 
  </code></pre>
  </blockquote>
  
  <p>Here are the outputs:</p>
  
  <ul>
  <li><code>"args": ["-p"],</code>     </li>
  <li><code>"args": ["-p", "."],</code></li>
  </ul>
  
  <blockquote>
    <p>error TS5023: Unknown compiler option 'p'.</p>
  </blockquote>
  
  <ul>
  <li><code>"args": ["."],</code></li>
  </ul>
  
  <blockquote>
    <p>error TS6053: File '.ts' not found.</p>
  </blockquote>