Reputation: 12395
I find many tsconfig.json samples always have compilerOptions
like this
"module": "commonjs",
"moduleResolution": "node"
I feel setting them both as such seems unnecessary because if moduleResolution
is node
the module
is definitely commonjs
. The module
is commonjs
, moduleResolution
is definitely node
too (I can't think of any other case)
Isn't that is the case?
--- update ---
Now I realize it is not always the case because nodejs has fully support ES Modules, so I can use "module": "ES2020" & "moduleResolution": "node"
(for nodejs 14+) but of course if I set "module":"commonjs"
I don't need to set "moduleResolution": "node"
Further refer to What TypeScript configuration produces output closest to Node.js 14 capabilities?
Upvotes: 1
Views: 14733
Reputation: 33701
Being explicit about configuration can prevent undesired behavior if a default value changes in the future in a breaking way.
The documentation explains the relationships between these configuration properties. I'll inline the default behaviors below:
Default:
Classic
if module isAMD
,UMD
,System
orES6
/ES2015
,Matches if module is
node12
ornodenext
,
Node
otherwise.Allowed:
classic
node
Default:
CommonJS
if target isES3
orES5
,
ES6
/ES2015
otherwise.Allowed:
none
commonjs
amd
umd
system
es6
/es2015
es2020
es2022
esnext
node12
nodenext
Default:
ES3
Allowed:
es3
es5
es6
/es2015
es2016
es2017
es2018
es2019
es2020
es2021
esnext
Upvotes: 3