Skip to main content

Module module_resolver

Module module_resolver 

Source
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_kind outcomes.
  • 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§

ModuleResolver
Module resolver that implements TypeScript’s resolution algorithms
ResolvedModule
Result of module resolution

Enums§

ImportKind
Import syntax kind - determines which error codes to use for extensionless imports in Node16/NodeNext resolution.
ImportingModuleKind
Module kind for the importing file Determines whether to use “import” or “require” conditions
ModuleExtension
Module file extensions TypeScript can resolve
PackageType
Package type from package.json “type” field Used for ESM vs CommonJS distinction in Node16/NodeNext
ResolutionFailure
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 EcmaScript imports
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