4

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! :)

1

6 Answers 6

2

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

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the response, basarat! I checked both of these, and they are good; all my .ts files are surrounded by <TypeScriptCompile> elements in the .csproj, and I've configured AMD for both Debug and Release. I've also restarted Visual Studio several times in trying to make this work, but to no success. Any other thoughts?
See my response below. It was my installation. Thanks again!
2

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

3 Comments

Understood. But I would have figured that setting AMD in my project properties would have done that. Is this not the case?
I'm sorry, I might have misread your question. It seems you already knew about AMD and commonjs. Try compiling from command-line, this should work tsc file.ts --module amd. However I assume from your comments that the issue is VS related, with which I cannot help
Not a problem at all. :) See my response below. It was my installation, not anything I was specifically doing wrong in my code or setup.
2

basarat and froginvasion, thanks to you both for your help. :) It turns out that the problem was with my Visual Studio installation itself. I found that uninstalling Visual Studio 2013 Update 3, and rolling back to Update 2, fixed the issue. I'll be submitting a ticket with Microsoft to have this looked at if I can't find anything specific about it online. Regardless, whatever I find, I'll post here. I'll up-vote you both for your effort, and again, thanks so much!

8 Comments

Since you fixed it yourself, accept your own answer so people know it is solved ;).
I honestly thought I did. On the other hand, my browser was acting weird. Oh well. I've set it now. Thanks for the reminder! :)
I just updated to VS Upd 3 & WebEssentials, and I'm getting the same message. I can't even find documentation on setting --module in Visual Studio.
I can also confirm that Update 3 is the culprit. Was having the same problem and after uninstalling it and reinstalling Update 2 all was normal again. Jamie, have you made any report to Microsoft anywhere? If so I would like to vote for the resolution.
I have not yet, no. I've been extremely busy the last couple weeks, but should have time to do so this weekend. I'll post here the link for anyone that wants to take a look. Sorry for the delay! :)
|
2

Had the same problem...

I found a Typescript Build tab on the project properties. Module system was set to None. Toggling it to AMD fixed the problem for me.

This tab was off-screeen, and unknown to me -- I think new in Update 2 or 3. The --module message might mention where the setting is.

Comments

1

I have been struggling with this exact issue recently and it was right after applying the Visual Studio 2013 update 3.

Suddenly my AMD modules weren't compiling. The module was still set in the project properties and everything.

After beating my head against the wall I decided to comment out the TypeScriptModuleKind nodes in the csproj.

<TypeScriptModuleKind>amd</TypeScriptModuleKind>

Then, I reloaded the project and opened the typescript build tab. As expected, the module kind was set to none now. I re-set it to amd. Now when I re-build it succeeds.

I opened the .csproj file again to see if it added the TypeScriptModuleKind node and it did, just in a separate property group all by itself.

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptModuleKind>amd</TypeScriptModuleKind>
</PropertyGroup>

I hope this very strange fix works for everyone else getting the Cannot compile external modules unless the '--module' flag is provided. error.

2 Comments

Thanks for the update! I'll give this a try this weekend, and see how it works! I've moved on to implement the project differently, but will throw together a test app to play with this solution.
I can confirm this worked for me as well. Though I had to do it a couple times for some no doubt magical reason
0

Just to add to this answer, there's a github issue for this that mentions some potential fixes and problems:

  1. For me it was that there was 2 lines that looked like this:

And removing the first one seemed to fix it (builds on update 4 as well as update 2).

  1. Another suggestion is to update a line that looks like

to

<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets')" />

But that didn't seem to work for me.

  1. Another suggestion was to ensure that the amd declaration was before the typescript import line, like this:

<PropertyGroup> <TypeScriptModuleKind>amd</TypeScriptModuleKind> </PropertyGroup> <Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" condition="Exists('$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets')" />

Which I didn't try.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.