Course contentsShow
← TypeScript
Lesson 1110 of 1,79626. Modules in TypeScriptFree lesson

What Module Resolution Means

Understanding how TypeScript finds and loads modules when you write import statements.

What Module Resolution Means

You'll learn: How TypeScript locates and loads the files referenced in your import statements.

The Core Problem

When you write import { User } from './types', you're giving TypeScript a clue, not a complete file path. Module resolution is the algorithm TypeScript uses to translate that import path into an actual file on your system.

Think of it like giving someone directions using landmarks instead of GPS coordinates. "Go to the coffee shop on Main Street" requires your listener to know which coffee shop, which Main Street, and how to navigate there. Module resolution does this work for your imports.

What TypeScript Needs to Figure Out

When TypeScript encounters an import statement, it must answer:

  1. Where is this module? (Which directory, which file?)
  2. What file extension? (.ts, .tsx, .d.ts, .js?)
  3. Is this a relative path or a package? ('./user' vs 'lodash')
  4. Which resolution strategy should I use? (The rules can vary)

Why This Matters

Different environments have different conventions. Node.js looks for modules in node_modules folders. Browsers need explicit file paths. Bundlers like Webpack add their own resolution logic. TypeScript needs to simulate whatever system your code will eventually run in, so it can type-check your imports correctly at compile time.

If TypeScript can't resolve an import, you'll get errors like Cannot find module './types' — even if the file exists. This happens when TypeScript's resolution strategy doesn't match where your files actually are.

Key Takeaway: Module resolution is TypeScript's process of turning import paths into actual file locations using configurable rules that mirror your runtime environment.