Expand description
Module Resolution Implementation
This module implements TypeScript’s module resolution algorithms:
- Node (classic Node.js resolution)
- Node16/NodeNext (modern Node.js with ESM support)
- Bundler (for webpack/vite-style resolution)
The resolver handles:
- Relative imports (./foo, ../bar)
- Bare specifiers (lodash, @scope/pkg)
- Path mapping from tsconfig (paths, baseUrl)
- Package.json exports/imports fields
- TypeScript-specific extensions (.ts, .tsx, .d.ts)
Resolver invariants:
- Module existence truth comes from
resolve_with_kindoutcomes. - Diagnostic code selection for module-not-found family (TS2307/TS2792/TS2834/TS2835/TS5097/TS2732) is owned here and propagated to checker via resolution records.
- Callers should not recompute not-found codes/messages from partial checker state.
Structs§
- Module
Resolver - Module resolver that implements TypeScript’s resolution algorithms
- Resolved
Module - Result of module resolution
Enums§
- Import
Kind - Import syntax kind - determines which error codes to use for extensionless imports in Node16/NodeNext resolution.
- Importing
Module Kind - Module kind for the importing file Determines whether to use “import” or “require” conditions
- Module
Extension - Module file extensions TypeScript can resolve
- Package
Type - Package type from package.json “type” field Used for ESM vs CommonJS distinction in Node16/NodeNext
- Resolution
Failure - Reason why module resolution failed
Constants§
- CANNOT_
FIND_ MODULE - TS2307: Cannot find module
- IMPORT_
PATH_ NEEDS_ EXTENSION - TS2834: Relative import paths need explicit file extensions in
EcmaScriptimports - IMPORT_
PATH_ NEEDS_ EXTENSION_ SUGGESTION - IMPORT_
PATH_ TS_ EXTENSION_ NOT_ ALLOWED - JSON_
MODULE_ WITHOUT_ RESOLVE_ JSON_ MODULE - TS2732: Cannot find module. Consider using ‘–resolveJsonModule’ to import module with ‘.json’ extension.
- MODULE_
RESOLUTION_ MODE_ MISMATCH - TS2792: Cannot find module. Did you mean to set the ‘moduleResolution’ option to ‘nodenext’?
- MODULE_
WAS_ RESOLVED_ TO_ BUT_ JSX_ NOT_ SET