TypeScript Compiler Diagnostics

TS5097: TypeScript extension import is not enabled

The import specifier ends in a TypeScript source extension (.mts here) while the shown emitting configuration does not permit that extension. For a normal Node ESM build, write the emitted .js or .mjs specifier; TypeScript can resolve it to the corresponding source. Other workflows may intentionally use allowImportingTsExtensions or rewriteRelativeImportExtensions under their own constraints. Baseline: TypeScript 5.8.3 with the shown configuration. Reproduce in one directory and create the corrected project in another. The diagnostic can have other causes; inspect its location and message before choosing a correction. Both projects keep strict checking enabled.

Formal Syntax & Structure

typescript syntaxtypescript
TS5097 (compiler diagnostic code, not TypeScript syntax)

Working Example

Example Snippettypescript
// INTENTIONALLY INVALID — reproduce// File: tsconfig.json (omit this label){  "compilerOptions": {    "strict": true,    "target": "ES2022",    "module": "NodeNext",    "types": [],    "lib": [      "ES2022",      "DOM"    ],    "noEmitOnError": true,    "outDir": "dist",    "moduleResolution": "NodeNext"  },  "files": [    "main.mts"  ]}
// File: main.mts (omit this label)import { value } from "./dep.mts";console.log(value);
// File: dep.mts (omit this label)export const value = 8;
// Run: tsc -p . --pretty false// Expected: TS5097; no output emitted.
// CORRECTED PROJECT — separate directory// File: tsconfig.json (omit this label){  "compilerOptions": {    "strict": true,    "target": "ES2022",    "module": "NodeNext",    "types": [],    "lib": [      "ES2022",      "DOM"    ],    "noEmitOnError": true,    "outDir": "dist",    "moduleResolution": "NodeNext"  },  "files": [    "main.mts"  ]}
// File: main.mts (omit this label)import { value } from "./dep.mjs";console.log(value);
// File: dep.mts (omit this label)export const value = 8;
// Run: tsc -p . --pretty false// Expected: no diagnostics.// Run: node dist/main.mjs// Expected stdout: 8
TypeScript Reference