7
votes

Editing a typescript project, that was created on VisualStudio, in WebStorm is replying this error:

Error:(1, 1) TS1148: Cannot compile external modules unless the '--module' flag is provided.

the code is simple like this:

in file Test.ts

class helloWorld{

}

export = helloWorld;

Thanks in advance for your help

EDITED

I forgot to mention that I was using a MAC.

Also after enter the post, on my quest to find the solution, I try to compile the web in VisualStudio Code for Mac, and I have the same problem there, that, make realize that the problem was not the IDE but something in common, that I didn't figure it out.

On fedemp answer this sentence trigger someting:

One is using the flag at compilation: tsc --module commonjs or --module amd.

So I go to Webstorm's Preferences -> Languages & Frameworks -> TypeScript and on the option "Command line options:" I added --module amd and done!

2
I had the exact same error but in IntelliJ on PC (virtually same as webstorm I think) 14.1.3 after importing a TS project that was working fine outside of IntelliJ. Solved by File->Settings->Languages & Frameworks-> Typescript and adding --module commonjs to the 'command line options:' - delp

2 Answers

6
votes

Check this: http://www.typescriptlang.org/Handbook#modules-export- It's the official documentation for Typescript, the section about export =.

When you use export =, you are creating an external module to be consumed using AMD or CommonJS. That's why the compiler complains.

You have to two options depending on your needs. One is using the flag at compilation: tsc --module commonjs or --module amd. Use this if you want to use NodeJS or require.js.

The other is export class HelloWorld {... if you want to use your class in another typescript file.

8
votes

For those of you that 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 Module System section change None to AMD.