Skip to content
Latchkey

TS2307: Cannot find module - in CI

tsc could not resolve an import to a module or to type declarations for it.

What this error means

Type-checking fails with TS2307 naming the import that could not be resolved. It is deterministic and reproduces every run.

tsc
src/app.ts(3,21): error TS2307: Cannot find module './utils' or its corresponding type declarations.

Common causes

How to fix it

Install the package and its types

  1. Add the dependency and, if it ships no types, its @types package
  2. Commit the lockfile so CI installs the same tree
shell
npm i lodash
npm i -D @types/lodash

Configure path aliases and moduleResolution

  1. Declare baseUrl and paths in tsconfig
  2. Pick a modern moduleResolution (bundler or nodenext)
tsconfig.json
{
  "compilerOptions": {
    "baseUrl": ".",
    "moduleResolution": "bundler",
    "paths": { "@/*": ["src/*"] }
  }
}

Fix path casing for Linux runners

  1. CI runs on case-sensitive Linux; match the exact filename case in the import

How to prevent it

  • Install @types for any untyped dependency, keep tsconfig paths in sync with your bundler aliases, and run tsc --noEmit in CI.

Frequently asked questions

What causes "TS2307 cannot find module"?
Type-checking fails with TS2307 naming the import that could not be resolved. It is deterministic and reproduces every run.
How do I fix TS2307 cannot find module?
Install the package and its types

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card