Typescript and webstorm, missing the -module flag

Editing the typescript project created on VisualStudio in WebStorm responds to this error:

Error: (1, 1) TS1148: it is not possible to compile external modules unless the '-module' flag is provided.

the code is simple:

in the file Test.ts

class helloWorld{ } export = helloWorld; 

Thanks in advance for your help.

EDITED

I forgot to mention that I used a MAC.

In addition, after entering the message, in my quest to find a solution, I try to compile web pages in VisualStudio Code for Mac, and I have the same problem that, understand that the problem is not in the IDE, but that I did not understand this.

At fedemp, answer this offer:

One uses the flag when compiling: tsc --module commonjs or --module amd.

So, I go to the Webstorm settings β†’ Languages ​​and framework β†’ typescript and the option β€œCommand line options:” I added --module amd and did it!

+7
javascript webstorm typescript
source share
2 answers

Note this: http://www.typescriptlang.org/Handbook#modules-export- This is the official documentation for Typescript, section on export = .

When you use export = , you create an external module that you want to use using AMD or CommonJS. This is why the compiler complains.

You have two options, depending on your needs. One uses the flag when compiling: tsc --module commonjs or --module amd . Use this if you want to use NodeJS or require.js.

Another export class HelloWorld {... if you want to use your class in another typescript file.

+6
source share

For those of you who are using VisualStudio, I did the following on VS2015 and the error went away.

Right-click on the project in Solution Explorer β†’ Properties β†’ TypeScript Build (last tab on the left - below Code Analysis) in the "System Modules" section, change "No" to "AMD".

+8
source share

All Articles