Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript external module

I'm using Visual Studio 2013 Update 3, and have the latest version of WebEssentials installed. Under my project settings, under the Typescript Build tab, I've set the Module system type to AMD. I have a Typescript file with the following simple code:

export class Test {
}

When I try to build, however, I get the following build error (which also shows up as a red squiggly in my editor): Cannot compile external modules unless the '--module' flag is provided.

I've been searching for an answer to this, but it seems like everything online is for pre 1.0 versions of Typescript, and don't seem to apply to my needs. Has anyone seen this behavior before, and if so, how did you resolve it?

Thanks in advance for any help! :)

like image 527
Jamie Nordmeyer Avatar asked Jan 11 '23 02:01

Jamie Nordmeyer


2 Answers

Make sure that the file is included in visual studio as <TypeScriptCompile

Also make sure your settings are for both Debug and Release.

like image 186
basarat Avatar answered Jan 12 '23 14:01

basarat


The module flag needed refers to what module loader that should be used in order to compile your code. As you might or might not know, there is AMD and commonjsstyle modules. The file you specified is a module, and in order to refer to it in another TypeScript file, you should define the module loader. This is because TypeScript compiles to JavaScript.

This means you have two options for the module flag:

  • commonjs
  • amd

I suggest you look them up if you don't know anything about them. If you go to TypeScript Playground, http://www.typescriptlang.org/Playground#src=export%20class%20Test%20%7B%0D%0A%7D You'll see that this does compile. Playground takes amd as module flag to compile.

What you want to choose thus depends on whether you are developing for the browser or in node.js.

Hope that helps

like image 33
froginvasion Avatar answered Jan 12 '23 15:01

froginvasion