a blog for those who code

Wednesday 15 July 2015

[Solved] Typescript Compilation Error TS5037 : Cannot compile external modules

In this post we are going to learn about fixing Typescript Compilation Error TS5037 : Cannot compile external modules unless the '--module' flag is provided. The error is self explanatory as that to compile the external modules you need to provide the '--module' flag.

Typescript has a concept of external modules which is actually required when you are using node.js or require.js To compile an typescript application which has external modules you need to add --module flag like below :

tsc your_file_name.ts --module "commonjs"

Now you might be wondering that why you need to do that. The simple answer is in Typescript (from TSC 0.9.1) the default module option is amd (common module pattern for client side). So for that to work you must specify the module option to get commonjs code which is the most common module pattern for server side javascript (nodejs). Because of that compiler is prompting you to specify your target.

If you are working on Visual Studio and getting this error then you need to specify the Module System as AMD under project settings. Go To Properties of the TypeScript Project and then change Module System as AMD as shown below.

You also have to set the Automatically compile Typescript files which are not part of a project to "Use amd code generation for modules that are not part of a project". To do that you need to go to Tools -> Options -> Text Editor -> TypeScript -> Project -> General and change like below.

Please Like and Share the Blog, if you find it interesting and helpful.

No comments:

Post a Comment