Error Encyclopedia
TS7016

TS7016: Could not find a declaration file for module

Fix TypeScript error TS7016 'Could not find a declaration file for module'. Learn to install @types, create custom .d.ts files, and configure typeRoots.

What Does This Error Mean?

TypeScript error TS7016 occurs when you import a JavaScript module that has no type declarations (.d.ts files). TypeScript needs type information for all imported modules when noImplicitAny is enabled. Without declarations, TypeScript does not know the shape of the module's exports.

Common Causes

1

The npm package does not include bundled TypeScript declarations

2

No corresponding @types/package exists for the library

3

The @types/package is not installed or is an incompatible version

4

A local JavaScript module lacks a .d.ts declaration file

5

typeRoots or types in tsconfig.json does not include the right paths

6

The module uses 'export default' but you imported it incorrectly

How to Fix It

Install @types if available

Most popular libraries have type definitions on DefinitelyTyped.

# Install type definitions
npm install --save-dev @types/lodash
npm install --save-dev @types/react
npm install --save-dev @types/express

# Check if types exist at:
# https://www.npmjs.com/search?q=%40types%2Fpackage-name

Create a custom declaration file

Create a .d.ts file to declare the module's types.

// custom.d.ts (in your project root or a types folder)
declare module "some-legacy-lib" {
  export function doSomething(input: string): void
  export const VERSION: string
  export default class LegacyAPI {
    constructor(options: Record<string, unknown>)
    run(): Promise<boolean>
  }
}

// Also include in tsconfig.json
// "include": ["src/**/*", "custom.d.ts"]

Use a quick ambient declaration

For quick fixes, declare the module as any to bypass type checking.

// global.d.ts
declare module "some-untyped-lib"  // Module typed as any

// This suppresses TS7016 but gives no type safety
import someLib from "some-untyped-lib"
// someLib is typed as any

Configure typeRoots in tsconfig

Ensure TypeScript knows where to look for type declarations.

{
  "compilerOptions": {
    "typeRoots": [
      "./node_modules/@types",  // Default location
      "./src/types"              // Custom types folder
    ],
    "types": ["node", "express"],  // Auto-include specific @types
    "skipLibCheck": true            // Skip checking .d.ts files (faster)
  }
}

Related Tools

Use these tools to debug and fix this error:

Related Errors

Other common errors in this category:

Frequently Asked Questions

Why do some packages not need @types?

Some packages include their own TypeScript declarations (bundled in the package or published as .d.ts files). Check the package's package.json for 'types' or 'typings' field. Modern libraries written in TypeScript often ship declarations.

What if no @types package exists?

You can either: (1) create a custom .d.ts file, (2) use `declare module 'name'` to type it as any, (3) set skipLibCheck to true, or (4) contribute types to DefinitelyTyped for the community.