Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot compile modules unless the --module flag is provided

UPDATE:The issue I had at the time was due to a bug in VS/Typescript. This issue is now resolved. Currently, the only reason for this error to occur is that no module type has been selected in Typescript properties. See accepted answer.

VS 15: asp.net MVC project.

I add a typescript file. I then set the Module system to System.

I then build the project.

The error occurs: Cannot compile modules unless the --module flag is provided.

I then check the properties of the ts file. I set the build action to none. The error goes away.

However, if I start with a fresh Typescript project using the template with the Greeter class, then all works as expected.

But I have looked at the project settings carefully, and there are no differences that I can see.

I have read all other stack overflow answers on this error and none of them have resolved the error.

The only workaround I have found is setting "Compile On Save" to true, and then setting the build action to "None"

like image 859
Greg Gum Avatar asked Aug 23 '15 18:08

Greg Gum


2 Answers

1 Open project properties (right click on your project in the Solution Explorer, and click "Properties").

2 Open the TypeScript tab.

3 Choose AMD in the module system section.

like image 141
MarzSocks Avatar answered Oct 19 '22 12:10

MarzSocks


So, we have this happen to us all of the time, but for different reasons. We offload all of our typescript compilation to gulp (which is called by a PreBuildEvent), so the compilation works fine, but we still get this error when viewing the file in Visual Studio.

Basically, we need to tell Visual Studio that we're using AMD, so to accomplish that, do the following:

  • In Visual Studio, go to Tools > Options > Text Editor > TypeScript > Project
  • Check "Automatically compile TypeScript files which are not part of a project"
  • Check "Use AMD code generation for modules that are not part of a project"

At that point, you can even uncheck the "Automatically compile ...." option, its just the 2nd one that needs to stay checked.

Again, when we encounter the issue, its a development time issue only and doesn't impact our builds (either locally or on our build servers).

like image 26
Allen Rice Avatar answered Oct 19 '22 13:10

Allen Rice