TypeScript and module option set to es2015/es2020/esnext

Viewed 2331

This is my tsconfig.json file:

{
    "compilerOptions": {
        "target": "es5",
        "module": "esnext",
    }
}

and my file test.ts:

module.exports.a = 4;

Then I run yarn tsc and surpisingly in my output file test.js I still have

module.exports.a = 4;

Question: Why the content of output file is not using esnext modules? Why isn't it export const a = 4?

Btw, if I go other way - module set to commonjs and test.ts with export const a = 4 the output file is generated correctly with cjs modules.

Why ts can compile modules from es to cjs and not from cjs to es ? If indeed TS can not do it then why do we have module option anyway?

0 Answers
Related