Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using external modules in Visual Studio 2015 CTP6 + TypeScript 1.4

I'm trying to figure out how to import modules. When I write a statement at the top of my .ts file such as:

import a = require("a");

I get the following error:

Cannot compile external modules unless the '--module' flag is provided.

In previous versions of Visual Studio, there was an area with the Project's properties that allowed you to control some TypeScript configuration. Where is this located in Visual Studio 2015?

Does anyone know how I can enable importing external modules?

like image 633
jgo Avatar asked Mar 26 '15 15:03

jgo


1 Answers

Here are the steps to configure typescript per project:

  1. Unload your project. If your project is based on the MVC 6 template, you will find that the MSBuild configuration is pretty minimal.

  2. Navigate to: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript*

    * This assumes you installed VS in the default location.

  3. Locate the Microsoft.TypeScript.Default.props file and open it up. No need for elevated privileges, we will only be reading from it.

    It should look something like:

    <?xml version="1.0" encoding="utf-8" ?>
    <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <TypeScriptTarget>ES5</TypeScriptTarget>
        <TypeScriptCompileOnSaveEnabled>true</TypeScriptCompileOnSaveEnabled>
        <TypeScriptNoImplicitAny>false</TypeScriptNoImplicitAny>
        <TypeScriptModuleKind>none</TypeScriptModuleKind>
        <TypeScriptRemoveComments>false</TypeScriptRemoveComments>
        <TypeScriptOutFile></TypeScriptOutFile>
        <TypeScriptOutDir></TypeScriptOutDir>
        <TypeScriptGeneratesDeclarations>false</TypeScriptGeneratesDeclarations>
        <TypeScriptSourceMap>true</TypeScriptSourceMap>
        <TypeScriptMapRoot></TypeScriptMapRoot>
        <TypeScriptSourceRoot></TypeScriptSourceRoot>
        <TypeScriptNoEmitOnError>true</TypeScriptNoEmitOnError>
      </PropertyGroup>
    </Project>
    
  4. Copy the entire PropertyGroup element, and paste it somewhere in your .kproj file; it needs to be under the Project element.

  5. Modify the TypeScriptModuleKind from none to your module definition. The options are AMD or CommonJS.

  6. Save the .kproj file, and reload your project.

You should no longer get the compile-time error about including modules.

like image 58
jgo Avatar answered Nov 20 '22 12:11

jgo