Skip to content
Latchkey

tsc TS7016: Could not find a declaration file for module 'X' in CI

TS7016 fires when a module is found on disk but has no .d.ts, so its import would be typed any. With noImplicitAny on (the default under strict), tsc turns that implicit any into an error.

What this error means

tsc reports "error TS7016: Could not find a declaration file for module 'X'. '.../X.js' implicitly has an 'any' type." with a hint to try npm i --save-dev @types/X if it exists.

tsc
src/index.ts:2:19 - error TS7016: Could not find a declaration file for module 'legacy-lib'.
'/app/node_modules/legacy-lib/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/legacy-lib` if it exists or add a new declaration (.d.ts) file
  containing `declare module 'legacy-lib';`

Common causes

A JavaScript-only package with no bundled or DefinitelyTyped types

The module resolves to a .js file, ships no .d.ts, and has no @types stub on the registry, so tsc has nothing to type-check the import.

noImplicitAny escalates the implicit any to an error

Locally the project may run loose, but the CI tsconfig enables strict/noImplicitAny, so the otherwise-silent implicit any becomes a hard error.

How to fix it

Add a minimal ambient declaration

  1. Create a .d.ts file included by your tsconfig.
  2. Declare the module so tsc treats it as a typed (any) module.
  3. Re-run tsc to confirm TS7016 clears.
types/legacy-lib.d.ts
// types/legacy-lib.d.ts
declare module 'legacy-lib';

Install a real @types stub if one exists

Prefer real declarations over a blanket any module when DefinitelyTyped publishes them.

Terminal
npm install --save-dev @types/legacy-lib

How to prevent it

  • Add ambient .d.ts files for JS-only dependencies you intend to keep.
  • Keep one types/ directory in include so ambient declarations are picked up in CI.
  • Prefer libraries that ship their own types when adding new dependencies.

Frequently asked questions

What causes "TS7016 "Could not find a declaration file""?
The module resolves to a .js file, ships no .d.ts, and has no @types stub on the registry, so tsc has nothing to type-check the import.
How do I fix TS7016 "Could not find a declaration file"?
Add a minimal ambient declaration

Related guides

References

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