Disable type checking for node_modules in TypeScript

avatar

Borislav Hadzhiev

Last updated: Mar 12, 2022

banner

Photo from Unsplash

Disable type checking for node_modules in TypeScript #

To disable type checking for node_modules in TypeScript, set the skipLibCheck property to true in your tsconfig.json file and make sure you're using a recent version of TypeScript. The skipLibCheck setting will skip type checking for all declaration (.d.ts) files.

Open your tsconfig.json file and set the skipLibCheck property to true.

tsconfig.json
{ "compilerOptions": { "skipLibCheck": true, // ... other settings } }

The skipLibCheck option instructs the TypeScript compiler to skip type checking for declaration (.d.ts) files.

You can achieve the same result by passing the --skipLibCheck flag when using the command line.

shell
tsc --skipLibCheck

If the errors are not resolved, make sure that the exclude array in your tsconfig.json file contains the path to your node_modules directory.

tsconfig.json
{ "compilerOptions": { "skipLibCheck": true, // ... other settings }, "include": ["src/**/*"], "exclude": ["node_modules"] }
Make sure that you're using a recent version of TypeScript. as the skipLibCheck option does not work for some older versions.

When the skipLibCheck option is set to false, you often encounter issues when there are multiple copies of a library's types in your node_modules directory.

It also might be that two libraries define copies of the same type in an inconsistent way.

When skipLibCheck is set to true, you often end up saving time during compilation.

Even though the setting disables type checking for d.ts files, TypeScript still type checks the code you specifically refer to in your application's source code.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.