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.
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
- Create a
.d.tsfile included by your tsconfig. - Declare the module so tsc treats it as a typed (any) module.
- Re-run tsc to confirm TS7016 clears.
// 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.
npm install --save-dev @types/legacy-libHow to prevent it
- Add ambient
.d.tsfiles for JS-only dependencies you intend to keep. - Keep one
types/directory inincludeso ambient declarations are picked up in CI. - Prefer libraries that ship their own types when adding new dependencies.