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