Skip to content
Latchkey

TypeScript Cannot Find a Package’s Types - Fix "exports"/typesVersions in CI

When a package ships an exports map, TypeScript resolves its types through that map under moduleResolution: node16/nodenext/bundler. If the package omits a types export condition (or its typesVersions does not match), the type-check fails to find declarations even though the JS resolves fine.

What this error means

A type-check or build fails with "Could not find a declaration file for module" or "has no exported member", only under modern moduleResolution. The runtime import works; TypeScript cannot follow the package’s exports/typesVersions to its .d.ts.

tsc output
error TS7016: Could not find a declaration file for module 'some-pkg'.
'/app/node_modules/some-pkg/dist/index.js' implicitly has an 'any' type.
There are types at '/app/node_modules/some-pkg/dist/index.d.ts', but this result
could not be resolved under your current 'moduleResolution' setting.

Diagnose it: what is different about the runner?

A build that passes locally and fails on a runner differs in a small number of predictable ways. Check those before changing build configuration, because the build config is usually not the thing that changed.

.github/workflows/ci.yml
- run: |
    node --version && npm --version
    echo "NODE_ENV=$NODE_ENV  CI=$CI"
    nproc && free -h && df -h /
    ls -la node_modules/.bin | head

Common causes

The package’s exports map lacks a types condition

Under node16/nodenext/bundler resolution, TypeScript looks for a types (or import/require with co-located .d.ts) condition in exports. A package missing it cannot have its types found through the map.

typesVersions or moduleResolution mismatch

A typesVersions block that does not match your TypeScript version, or a tsconfig moduleResolution that disagrees with how the package publishes types, breaks resolution.

How to fix it

Align moduleResolution and add the missing condition

Set a resolution mode the package supports; for your own package, add a types condition to exports.

tsconfig.json / package.json
// tsconfig.json - match how the dep ships types
{ "compilerOptions": { "moduleResolution": "bundler" } }

// for a package YOU publish, expose types in exports:
"exports": { ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" } }

Work around an unfixable upstream package

  1. Check whether an @types/<pkg> package exists and install it.
  2. Add a local ambient declare module "some-pkg" declaration if no types are published.
  3. File an issue upstream to add the types export condition.

The three that account for most of them

  • Case sensitivity. Linux runners are case sensitive, macOS is not. An import with the wrong case resolves locally and fails in CI.
  • Out of memory. Exit code 137 is a SIGKILL from the kernel, not a build error. Raise --max-old-space-size or use a larger runner.
  • devDependencies pruned. NODE_ENV=production makes npm ci skip devDependencies, so the build tool itself goes missing. Set it after install, not before.

How to prevent it

  • Choose a moduleResolution matching how your deps ship types.
  • In your own packages, include a types condition in exports.
  • Add ambient declarations only as a temporary shim.

Frequently asked questions

What causes TypeScript cannot find a Package’s types?
There are 2 common causes: the package’s exports map lacks a types condition and typesversions or moduleresolution mismatch. Under node16/nodenext/bundler resolution, TypeScript looks for a types (or import/require with co-located .d.ts) condition in exports.
How do I fix TypeScript cannot find a Package’s types?
There are 2 fixes depending on which cause you have: align moduleresolution and add the missing condition and work around an unfixable upstream package. Work through them in order, since the first is the most common.
What does TypeScript cannot find a Package’s types actually mean?
A type-check or build fails with "Could not find a declaration file for module" or "has no exported member", only under modern moduleResolution.
How do I stop TypeScript cannot find a Package’s types happening again?
Choose a moduleResolution matching how your deps ship types. The prevention section lists 3 changes that keep it from recurring.

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