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.
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
- For Node ESM/CJS interop, use
nodenext(withmodule: nodenext). - For a bundler that reads
exports, usebundler. - Re-run tsc so the package resolves through its exports map.
{
"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.
{
"compilerOptions": { "module": "ESNext", "moduleResolution": "bundler" }
}How to prevent it
- Keep
moduleandmoduleResolutionaligned with your runtime or bundler. - Use
nodenextorbundlerfor packages withexportsmaps. - Avoid the legacy
node(classic) resolution for modern dependencies.