error TS7016: Could not find a declaration file for module 'legacy-slugify'. '/project/node_modules/legacy-slugify/index.js' implicitly has an 'any' type. is reported when an import resolves to a package's JavaScript but no type declarations: no types in its package.json, no .d.ts next to it, no @types package. Under noImplicitAny the resulting any is an error.
A jsconfig.json makes this rarer than in TypeScript projects: it sets maxNodeModuleJsDepth to 2, so the checker reads the package's own JavaScript (and its JSDoc) for types. You meet TS7016 in a tsconfig.json with allowJs, with maxNodeModuleJsDepth: 0 as in the example, or for packages deeper than the limit.
At a glance
| Code | TS7016 |
|---|---|
| Message | Could not find a declaration file for module '{0}'. '{1}' implicitly has an 'any' type. |
| TypeScript's category | error |
| Listed under | Modules and imports |
| Turned on by | noImplicitAny, strict |
| Turned off by | maxNodeModuleJsDepth |
| In .js files | Reported when the file is checked: checkJs in jsconfig.json, or // @ts-check at the top of the file |
The message is TypeScript's own text from its diagnostic messages file (Apache-2.0); {0} and {1} are filled in by tsc for each error.
What it looks like
import { slugify } from "legacy-slugify";error TS7016: Could not find a declaration file for module 'legacy-slugify'. '/project/node_modules/legacy-slugify/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/legacy-slugify` if it exists or add a new declaration (.d.ts) file containing `declare module 'legacy-slugify';`
export const slug = slugify("Cotton tee");jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": [],
"maxNodeModuleJsDepth": 0
},
"include": ["*.js"]
} What causes it
- The package publishes JavaScript only, and no
@types/<name>package is installed. - The checker is not reading packages' JavaScript:
maxNodeModuleJsDepthis 0 (thetsconfig.jsondefault) or the package is beyond the depth. noImplicitAnyis on (part ofstrict).
How to fix it
Install the @types package, if there is one
The message suggests npm i --save-dev @types/<name>. DefinitelyTyped publishes types for many JavaScript-only packages; a types: [] list in your config does not stop the import from finding it.
import { slugify } from "legacy-slugify";
export const slug = slugify("Cotton tee");jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": [],
"maxNodeModuleJsDepth": 0
},
"include": ["*.js"]
} Or write a small declaration file
Write a .d.ts file with declare module "legacy-slugify" { ... } describing just the functions you use, matched by include. declare module "legacy-slugify"; with no body also silences the error, but makes every import any.
import { slugify } from "legacy-slugify";
export const slug = slugify("Cotton tee");jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": [],
"maxNodeModuleJsDepth": 0
},
"include": ["*.js", "types/*.d.ts"]
} Or let the checker read the package's JavaScript
With the jsconfig.json default (maxNodeModuleJsDepth 2), the checker reads the package's files and takes types from their code and JSDoc. That works best for packages that are documented with JSDoc, like the one in this example.
import { slugify } from "legacy-slugify";
export const slug = slugify("Cotton tee");jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": ["*.js"]
} Gotchas
- When the checker reads a package's JavaScript, an untyped parameter inside the package is reported as TS7006 against the package's own file under
noImplicitAny, whether or not your code calls that function. A.d.tsor an@typespackage avoids that. - The path in the message is the file the import resolved to (tsc prints the full path; on this site examples live at
/project).
Sources
- TSConfig Reference: maxNodeModuleJsDepth · TypeScript
- Consumption (installing @types packages) · TypeScript handbook
- diagnosticMessages.json (TypeScript 5.9.3) · TypeScript on GitHub
Last reviewed 20 October 2026.