TypeScript Reference ยท tsconfig: Language, Modules and Emit Options
TypeScript maxNodeModuleJsDepth option
Reference for maxNodeModuleJsDepth: how deep the compiler follows untyped JavaScript packages in node_modules, why the default is 0 and when to raise it.
maxNodeModuleJsDepth sets how many levels of node_modules the compiler may look into for plain JavaScript files when a package ships no type declarations. The default is 0, which means: do not read JavaScript from node_modules at all. An import of an untyped package then has the type any (or is an error under noImplicitAny).
The option only has an effect together with allowJs. When both are on, the compiler reads the package's .js files, infers types from them and treats the package like source you could have written in TypeScript. That is slow and often gives vague types, so it is rarely worth it.
{ "compilerOptions": { "allowJs": true, "maxNodeModuleJsDepth": 1 } }
Try it
What the compiler infers from JavaScript is much weaker than what you write by hand. These examples show the shapes involved, using TypeScript code you could have received as a plain .js file.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Syntax
{ "compilerOptions": { "allowJs": true, "maxNodeModuleJsDepth": 2 } }
| Name | Description |
|---|---|
maxNodeModuleJsDepth |
A non-negative number. 0 (the default) ignores JavaScript inside node_modules; 1 reads a package's own files; larger values follow nested dependencies. |
Usage notes
- It does nothing unless
allowJsis on, and it never applies to your own source folders. - Raising it makes type-checking slower and can produce odd inferred types;
skipLibCheckdoes not help because the files are.js, not.d.ts. - A better fix for an untyped package is to install its
@types/...package, or write a smalldeclare module "name";declaration of your own. noImplicitAnyreports an untyped import as an error (TS7016) when the package has no declarations and depth is0.- The option is a niche setting: most projects leave it alone and never see its effect.