Classic vs Node Resolution Strategies
What you'll learn: How TypeScript's two primary module resolution algorithms differ and when each one is automatically applied.
Why Module Resolution Strategies Matter
When you write import { something } from "some-package", TypeScript needs to figure out where to find that module's type definitions. This process is called module resolution, and TypeScript has two different algorithms for doing it: Classic and Node.
Think of these as two different strategies for searching your house when you've lost your keys:
- Classic checks a few obvious places in a straight line
- Node mimics how Node.js searches, checking
node_modulesfolders up the directory tree
The Classic Strategy
Classic resolution is TypeScript's original and simplest approach. It's rarely used today but is still the default when you set "module": "AMD", "System", or "ES2015" (or higher) in your tsconfig.json without specifying moduleResolution.
For relative imports like import { x } from "./file", Classic looks for:
./file.ts./file.d.ts
For non-relative imports like import { x } from "package", Classic walks up the directory tree looking for matching files, but doesn't check node_modules at all.
The Node Strategy
Node resolution mimics Node.js's module resolution algorithm. This is the default for most modern TypeScript projects and is automatically selected when you use "module": "CommonJS", "Node16", or "NodeNext".
For non-relative imports, Node resolution checks node_modules folders at every level, looking for:
- Package
package.jsonwith atypesortypingsfield - An
index.d.tsfile in the package directory - Loose
.d.tsfiles matching the import path
This matches how npm install and require() work in Node.js.
When Each Strategy Is Used
- Classic: Only when explicitly set via
"moduleResolution": "classic"or implicitly triggered by older module formats (rarely used today) - Node: Default for most projects, especially those using
"module": "commonjs"or working with npm packages
Key Takeaway: Unless you're working with legacy code, you'll almost always use Node resolution, which automatically checks node_modules folders just like Node.js does. Classic resolution is mostly a historical artifact.