debugModeratepending
TypeScript 'Cannot find module' despite it being installed
Viewed 0 times
Cannot find moduletypesmoduleResolutionnode16bundlerexports
nodejstypescript
Error Messages
Problem
TypeScript reports 'Cannot find module' for an installed npm package. The package is in node_modules and works at runtime, but TypeScript cannot resolve it for type checking.
Solution
Common causes: (1) Package has no types — install @types/package-name. Check npmjs.com for 'DT' badge. (2) moduleResolution in tsconfig is wrong — use 'bundler' (modern) or 'node16'. Old 'node' resolution does not support package.json exports field. (3) Package uses exports field but your TS version is old — need TS 4.7+ with node16/nodenext. (4) Path alias misconfigured — paths in tsconfig must match bundler aliases. (5) Missing typeRoots — custom type directories need typeRoots config.
Why
TypeScript type resolution is separate from Node.js module resolution. A package can be importable at runtime but invisible to the type checker if types are missing or resolution strategy does not match.
Revisions (0)
No revisions yet.