TypeScript Compiler Options

module — TypeScript compiler option

Controls module emission and informs checking and resolution. Node-oriented modes choose output per file using extensions and package type; preserve keeps each import/export form. Match the runtime or bundler. Default (5.8.3): depends on target and settings. Create the labeled files in an isolated local project and run tsc -p tsconfig.json. Expected: no diagnostics; emitted files: main.js. Run node main.js; expected stdout: '7'. Local multi-file fixture, not a single-file editor.

Formal Syntax & Structure

typescript syntaxtypescript
{  "compilerOptions": {    "module": "CommonJS"  }}

Parameters & Attributes

NameTypeDescription
modulemodule format enumSet in compilerOptions; default: depends on target and settings.

Working Example

Example Snippettypescript
// File: tsconfig.json (omit this label){  "compilerOptions": {    "target": "ES2022",    "module": "CommonJS",    "strict": true,    "types": [],    "noEmitOnError": true  },  "files": [    "main.ts"  ]}// File: main.tsexport const value = 7; console.log(value);
TypeScript Reference