Unable to compile modules if -module flag is not specified

UPDATE: The problem I had at that time was due to a bug in VS / Typescript. This issue is now resolved. Currently, the only reason for this error to occur is the lack of module type selection in Typescript properties. See Accepted Answer.

VS 15: MVC asp.net project.

I am adding a Typescript file. Then I install the module system into the system.

Then I create a project.

An error occurs: it is not possible to compile modules if the -module flag is not specified.

Then I check the properties of the ts file. I set the assembly action to none. The error will disappear.

However, if I start with a new Typescript project using a template with the Greeter class, then everything will work as expected.

But I carefully studied the project settings, and I do not see the differences.

I read all the other answers to this error, and none of them resolved the error.

The only workaround I found was to set โ€œCompile on Saveโ€ to true, and then set the build action to โ€œNoโ€

+6
source share
3 answers

1 Open the project properties (right-click on the project in the solution explorer and select "Properties").

2 Click the TypeScript tab.

3 Select AMD in the system system section.

+7
source

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

Basically, we need to tell Visual Studio that we are using AMD, so to do this, follow these steps:

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

At this point, you can even disable the option "Automatically compile ....", its only the second, which should remain checked.

Again, when we encounter a problem, its a development-time problem and does not affect our builds (locally or on our build servers).

+5
source

Using VS 2013. Here's what solved mine.

Go to "Project Properties"> TypeScript Assembly> Select "AMD" as the module.

+1
source

All Articles