Using external modules in Visual Studio 2015 CTP6 + TypeScript 1.4

I am trying to figure out how to import modules. When I write an instruction at the top of my .ts file, for example:

import a = require("a"); 

I get the following error:

Unable to compile external modules if the -module flag is not specified.

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

Does anyone know how I can enable the import of external modules?

+7
visual-studio-2015 typescript
source share
1 answer

Following are the steps to configure typescript for each project:

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

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

    * It is assumed that you installed VS in the default folder.

  • Locate the Microsoft.TypeScript.Default.props file and open it. There is no need for elevated privileges, we will read only from it.

    It should look something like this:

     <?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> 
  • Copy the entire PropertyGroup element and paste it somewhere in the .kproj file; it should be under the project element.

  • Change the TypeScriptModuleKind from none to your module definition. Possible values: AMD or CommonJS .

  • Save the .kproj file and reload the project.

You should no longer receive a compile-time error with the inclusion of modules.

+5
source share

All Articles