aryzing
aryzing

Reputation: 5867

Difference between typescript module "None" and "CommonJS"

It seems that using tsc with compilerOptions.module set to None or CommonJS is producing the same transpiled code. How do these two differ? Why are there two options for producing (apparently) the same transpiled code?

Upvotes: 7

Views: 8984

Answers (1)

Shaun Luttin
Shaun Luttin

Reputation: 141512

With module set to None, we cannot use imports, exports, or module augmentations (except for the way that @artem notes in the below comments.)

Here is the source of the message.

"Cannot use imports, exports, or module augmentations when '--module' is 'none'.": {
    "category": "Error",
    "code": 1148
},

With module set to CommonJS, if we choose not to use imports, exports, or module augmentations, then our output might look the same as it does when we set module to None.

Upvotes: 7

Related Questions