Search code examples
node.jstypescriptwebstormamdcommonjs

TypeScript: how to tell WebStorm to use CommonJS rather than AMD


I'm using WebStorm to build a Node.js app in TypeScript. When I write a "require" statement, the TypeScript compiler uses AMD. I know it by the js output with the asynchronous pattern.

How can I tell WebStorm to use CommonJS instead?


Solution

  • You have to say that to compiler, for example in npm

    Option:

    -m, --module Specify module code generation: 'commonjs' or 'amd'

    Example:

    tsc.compile(['test/cases/ship.ts', 'test/cases/fleet.ts'], '-m commonjs -t ES5 --out test/tmp/navy.js');

    for more refer to: TypeScript compiler

    also have a look at this video: TypeScript Modules Demystified : Internal, AMD with RequireJS, CommonJS with NodeJS