Skip to content
Latchkey

TS2792: Cannot find module - try moduleResolution node - in CI

tsc could not resolve a module and suggests that your moduleResolution (or paths) setting is the cause.

What this error means

Type-checking fails with TS2792, explicitly recommending a moduleResolution change or paths aliases.

tsc
src/svc.ts(1,19): error TS2792: Cannot find module 'node:fs'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

Diagnose it: which tsconfig and which compiler?

A TypeScript error that appears only in CI usually means the runner is compiling with a different config or a different compiler version than your editor. Your editor uses the workspace TypeScript and the nearest tsconfig.json; CI uses whatever the lockfile resolved and whatever config the build script names.

Terminal
# what CI will actually use
npx tsc --version
npx tsc --showConfig | head -40

# which files are in the program (a missing include is a common cause)
npx tsc --listFiles | wc -l

# type-check only, no emit, same as most CI gates
npx tsc --noEmit

Common causes

How to fix it

Use a modern moduleResolution

  1. Set moduleResolution to bundler, node16, or nodenext to match your runtime
tsconfig.json
{
  "compilerOptions": {
    "module": "nodenext",
    "moduleResolution": "nodenext"
  }
}

Add paths aliases

  1. Declare baseUrl and paths for any custom specifiers
tsconfig.json
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": { "@/*": ["src/*"] }
  }
}

Pin the compiler so unrelated updates cannot break the gate

TypeScript adds errors in minor releases. An unpinned compiler turns a routine dependency update into a red build on code nobody touched, which is the most common false alarm in a TypeScript CI pipeline.

package.json
// package.json
{
  "devDependencies": {
    "typescript": "5.6.3"   // exact, not ^5.6.3
  }
}

How to prevent it

  • Choose a moduleResolution that matches your module format and keep paths aliases in sync with imports.

Frequently asked questions

How do I fix TS2792: cannot find module?
There are 2 fixes depending on which cause you have: use a modern moduleresolution and add paths aliases. Work through them in order, since the first is the most common.
What does TS2792: cannot find module actually mean?
Type-checking fails with TS2792, explicitly recommending a moduleResolution change or paths aliases.
How do I stop TS2792: cannot find module happening again?
Choose a moduleResolution that matches your module format and keep paths aliases in sync with imports.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card