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?
Here are the steps to configure typescript per project:
Unload your project. If your project is based on the MVC 6 template, you will find that the MSBuild
configuration is pretty minimal.
Navigate to:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript
*
* This assumes you installed VS in the default location.
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>
Copy the entire PropertyGroup
element, and paste it somewhere in your .kproj
file; it needs to be under the Project element.
Modify the TypeScriptModuleKind
from none to your module definition. The options are AMD
or CommonJS
.
Save the .kproj file, and reload your project.
You should no longer get the compile-time error about including modules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With