Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between typescript module "None" and "CommonJS"

Tags:

typescript

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?

like image 665
aryzing Avatar asked Aug 21 '17 18:08

aryzing


1 Answers

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.

like image 160
Shaun Luttin Avatar answered Oct 03 '22 04:10

Shaun Luttin