Greg Gum Greg Gum - 4 months ago 38
TypeScript Question

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: 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"


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.