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
- Add the dependency and, if it ships no types, its @types package
- Commit the lockfile so CI installs the same tree
shell
npm i lodash
npm i -D @types/lodashConfigure path aliases and moduleResolution
- Declare baseUrl and paths in tsconfig
- Pick a modern moduleResolution (bundler or nodenext)
tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"moduleResolution": "bundler",
"paths": { "@/*": ["src/*"] }
}
}Fix path casing for Linux runners
- 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.
Related guides
TS2792: Cannot find module - try moduleResolution node - in CIFix "error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', o…
TS7016: Could not find a declaration file for module - in CIFix "error TS7016: Could not find a declaration file for module 'x'. '...' implicitly has an 'any' type" when…
TS2688: Cannot find type definition file for - in CIFix "error TS2688: Cannot find type definition file for 'x'" when tsc runs in CI - a types entry that is not…