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.
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.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 - 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
- Check whether an
@types/<pkg>package exists and install it. - Add a local ambient
declare module "some-pkg"declaration if no types are published. - File an issue upstream to add the
typesexport condition.
How to prevent it
- Choose a moduleResolution matching how your deps ship types.
- In your own packages, include a
typescondition in exports. - Add ambient declarations only as a temporary shim.