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

Troubleshooting Common Resolution Errors

Fixing cannot find module errors, missing types, and mismatched configurations.

Troubleshooting Common Resolution Errors

You'll learn: How to diagnose and fix the most common module resolution problems TypeScript developers encounter.

What This Lesson Covers

You've configured module resolution, but TypeScript still can't find your modules. These errors are frustrating because the files exist, yet TypeScript insists they don't. Understanding the three main culprits—missing modules, missing types, and configuration mismatches—will save you hours of debugging.

The Three Common Resolution Errors

Cannot Find Module Errors

This happens when TypeScript can't locate the module file itself. Common causes:

  • Wrong file extensions: Your import uses .ts but should use .js (or no extension)
  • Incorrect relative paths: ../utils when it should be ../../utils
  • Missing baseUrl or paths configuration: Your path alias isn't set up in tsconfig.json
  • Case sensitivity: ./MyFile vs ./myFile works on Windows but breaks on Linux

Fix: Check your import path matches the actual file location. Use --traceResolution to see exactly where TypeScript is looking.

Missing Types

The module exists, but TypeScript has no type information for it. This occurs with:

  • JavaScript libraries without type definitions
  • Missing @types/ packages: Install @types/library-name
  • Package doesn't declare types in package.json

Fix: Install the corresponding @types package or create your own .d.ts file.

Mismatched Configurations

Your code works locally but breaks in CI, or vice versa. Usually caused by:

  • Different moduleResolution strategies between environments
  • Conflicting paths mappings
  • Missing exports field support when using modern packages

Fix: Ensure your tsconfig.json settings match across all environments. Use "moduleResolution": "bundler" or "node16" for modern setups.

Quick Diagnostic Checklist

  1. Verify the file actually exists where you think it does
  2. Check import path spelling and casing
  3. Confirm @types/ packages are installed for third-party libraries
  4. Review moduleResolution, baseUrl, and paths settings
  5. Run with --traceResolution to see the resolution process

Key Takeaway: Most resolution errors stem from path mistakes, missing type packages, or configuration inconsistencies between environments—systematic debugging with --traceResolution reveals the exact issue.