TypeScript Compiler Diagnostics

TS2307: Module cannot be resolved

The selected module resolution algorithm cannot locate a source or declaration for the specifier. Here the file exists under a different name. Confirm path spelling, package installation, exports and resolution settings before adding a declaration; a declaration alone does not install a runtime module. 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
TS2307 (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": "CommonJS",    "types": [],    "lib": [      "ES2022",      "DOM"    ],    "noEmitOnError": true,    "outDir": "dist"  },  "files": [    "main.ts"  ]}
// File: main.ts (omit this label)import { count } from "./missing";console.log(count);
// File: dep.ts (omit this label)export const count = 5;
// Run: tsc -p . --pretty false// Expected: TS2307; no emitted main file.
// CORRECTED PROJECT// File: tsconfig.json (omit this label){  "compilerOptions": {    "strict": true,    "target": "ES2022",    "module": "CommonJS",    "types": [],    "lib": [      "ES2022",      "DOM"    ],    "noEmitOnError": true,    "outDir": "dist"  },  "files": [    "main.ts"  ]}
// File: main.ts (omit this label)import { count } from "./dep";console.log(count);
// File: dep.ts (omit this label)export const count = 5;
// Run: tsc -p . --pretty false// Expected: no diagnostics.// Run: node dist/main.js// Expected stdout: 5
TypeScript Reference