TypeScript Compiler Diagnostics

TS2835: Missing ESM import extension

NodeNext ESM resolution requires explicit relative extensions in this context. TypeScript resolves ./dep.mjs to dep.mts and emits the original JavaScript extension for Node. Bundler resolution can have different rules. Baseline: TypeScript 5.8.3 with the shown configuration. Diagnose the reported location and nested message before applying a fix; other causes may require a different correction. The first project is intentionally invalid; create the corrected project separately. Neither example requires disabling strict checking.

Formal Syntax & Structure

typescript syntaxtypescript
TS2835 (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 { count } from "./dep";console.log(count);
// File: dep.mts (omit this label)export const count = 5;
// Run: tsc -p . --pretty false// Expected: TS2835; no emitted main file.
// CORRECTED PROJECT// 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 { count } from "./dep.mjs";console.log(count);
// File: dep.mts (omit this label)export const count = 5;
// Run: tsc -p . --pretty false// Expected: no diagnostics.// Run: node dist/main.mjs// Expected stdout: 5
TypeScript Reference