Skip to content
Latchkey

tsc TS2792: Cannot find module 'x'; did you mean to set moduleResolution to nodenext? in CI

TS2792 is a resolution-strategy mismatch: the module exists, but tsc's moduleResolution mode cannot locate it under the package's exports/conditions. tsc suggests switching to nodenext or bundler.

What this error means

tsc fails with "error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?" for a package that resolves fine in Node or the bundler.

tsc
src/index.ts:1:24 - error TS2792: Cannot find module 'nanoid'. Did you mean to set the
'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

1 import { nanoid } from 'nanoid';
                         ~~~~~~~~

Common causes

A package uses exports maps that classic resolution ignores

With moduleResolution: node (classic), tsc does not read the package exports field, so an ESM-only package with conditional exports appears unresolvable.

module and moduleResolution are out of step

A modern module setting with a stale moduleResolution value mismatches how the bundler or Node actually resolves the package.

How to fix it

Set moduleResolution to match your environment

  1. For Node ESM/CJS interop, use nodenext (with module: nodenext).
  2. For a bundler that reads exports, use bundler.
  3. Re-run tsc so the package resolves through its exports map.
tsconfig.json
{
  "compilerOptions": {
    "module": "nodenext",
    "moduleResolution": "nodenext"
  }
}

Use bundler resolution for a bundled app

If a bundler (Vite, esbuild, webpack) resolves the modules, the bundler mode reads exports without requiring extensions.

tsconfig.json
{
  "compilerOptions": { "module": "ESNext", "moduleResolution": "bundler" }
}

How to prevent it

  • Keep module and moduleResolution aligned with your runtime or bundler.
  • Use nodenext or bundler for packages with exports maps.
  • Avoid the legacy node (classic) resolution for modern dependencies.

Frequently asked questions

What causes "TS2792 "set the moduleResolution option""?
With moduleResolution: node (classic), tsc does not read the package exports field, so an ESM-only package with conditional exports appears unresolvable.
How do I fix TS2792 "set the moduleResolution option"?
Set moduleResolution to match your environment

Related guides

References

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