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

Quick answer

The JavaScript package you imported ships no TypeScript types, and noImplicitAny won't let it be silently any. Install the community types — npm i -D @types/<package>. If none exist, add a one-line declare module '<package>'; stub. Don't disable noImplicitAny to silence it.

The exact error string

import foo from "some-js-lib";
// error TS7016: Could not find a declaration file for module 'some-js-lib'.
// '.../some-js-lib/index.js' implicitly has an 'any' type.
//   Try `npm i --save-dev @types/some-js-lib` if it exists.

How to diagnose it

The message already tells you the next step — the question is just which of three situations you're in:

Fix 1: install the @types package

npm install --save-dev @types/some-js-lib

# scoped package? the @types name is flattened with __ :
# @babel/core  ->  @types/babel__core
npm install --save-dev @types/babel__core

Then restart the TypeScript server (in VS Code: "TypeScript: Restart TS Server") so the editor loads the new declarations.

Fix 2: no @types? add a declaration stub

// types/some-js-lib.d.ts   (must be inside your tsconfig "include")
declare module "some-js-lib";          // types it as any — import compiles

// or add minimal real types:
declare module "some-js-lib" {
  export function doThing(x: number): string;
}

Fix 3: installed but still failing

Worked example: a JS-only library in a React/TS app

You add a small plain-JS library (a carousel, a legacy SDK, an analytics shim) to a React + TypeScript project. It works at runtime but tsc and the editor flag the import:

import Carousel from "legacy-carousel";   // plain JS, no .d.ts
// error TS7016: Could not find a declaration file for module 'legacy-carousel'.

// 1) try community types:
//    npm i -D @types/legacy-carousel        (404? -> step 2)
// 2) stub it so the build passes today:
//    types/legacy-carousel.d.ts
declare module "legacy-carousel" {
  import { ComponentType } from "react";
  const Carousel: ComponentType<{ items: string[] }>;
  export default Carousel;
}

Note React itself never triggers TS7016 — @types/react provides its declarations. The error is specific to untyped dependencies you add.

Common variants of this message

SituationSignalFix
Community types existerror suggests @types/namenpm i -D @types/name
Scoped package@scope/pkg@types/scope__pkg
No types anywhere@types install 404sdeclare module 'pkg'; stub
Types ship with the lib"types" in its package.jsonfix typeRoots/restart TS server
Local JS file importrelative ./util.jsallowJs or write a .d.ts

Debugging checklist

Frequently Asked Questions

How do I find the right @types package name?

The error suggests it directly: 'Try npm i --save-dev @types/<name>'. For scoped packages the name is flattened with double underscores — @babel/core becomes @types/babel__core. If npm reports the @types package doesn't exist, the library has no community types and you need a declaration stub.

Why do some packages not need @types?

Many modern packages ship their own .d.ts files (look for a "types" or "typings" field in their package.json), so TypeScript finds types automatically and never raises TS7016. You only need @types or a stub for plain-JavaScript libraries that bundle no declarations.

What goes in a declare module stub?

At minimum, declare module 'pkg'; in a .d.ts file your tsconfig includes — that types the module as any so the import compiles. You can add real signatures incrementally: declare module 'pkg' { export function doThing(x: number): string }. Keep the file under an include path.

Why does it only fail in strict projects or CI?

TS7016 fires only when noImplicitAny (part of strict) is on. A non-strict project silently types the import as any and shows nothing. So the error is your config working correctly; install types rather than turning noImplicitAny off.

Is // @ts-ignore an acceptable fix?

Only as a temporary unblock. // @ts-ignore (or @ts-expect-error) above the import silences TS7016 but types the module as any, losing autocomplete and checking. Prefer @types or a declare module stub; if you must ignore, leave a TODO to add real types.

I installed @types but TS7016 persists — what now?

Check that it landed in the right node_modules (monorepos hoist differently), that tsconfig's typeRoots/types doesn't exclude node_modules/@types, that the @types name matches the import, and restart the TS server so the editor reloads. tsc and the editor share the check, so a stale server is a common cause.

More TypeScript & JSON errors

Browse the full reference, or generate accurate interfaces from your JSON.

JSON to TypeScript Error: Cannot find module All Error References
About the author

Pasindu Ishan is a software developer based in Sri Lanka. He builds privacy-first developer tools at JSON Dev Tools.