Reputation: 303
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!
Upvotes: 7
Views: 3742
Reputation: 161
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.
Upvotes: 8
Reputation:
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.
Upvotes: 6