How to force tsc to ignore node_modules folder? How to force tsc to ignore node_modules folder? typescript typescript

How to force tsc to ignore node_modules folder?


Quickfix is to skip the check

{  "compilerOptions": {    "skipLibCheck": true  },}


Add an empty "types" option in "compilerOptions":

{  "compilerOptions": {    "target": "es5",    "module": "commonjs",    "sourceMap": true,    "strict": false,    "noImplicitAny": false,    "strictPropertyInitialization": false,    "esModuleInterop": true,    "types": []  },  "include": [    "src/*"  ],  "exclude": [    "node_modules",    "./node_modules",    "./node_modules/*",    "./node_modules/@types/node/index.d.ts",  ]}

From https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

@types, typeRoots and types

By default all visible “@types” packages are included in your compilation. Packages in node_modules/@types of any enclosing folder are considered visible; specifically, that means packages within ./node_modules/@types/, ../node_modules/@types/, ../../node_modules/@types/, and so on.

...

Specify "types": [] to disable automatic inclusion of @types packages.

Keep in mind that automatic inclusion is only important if you’re using files with global declarations (as opposed to files declared as modules). If you use an import "foo" statement, for instance, TypeScript may still look through node_modules & node_modules/@types folders to find the foo package


I met this issue with typescript@3.2.1 and fixed by upgrading it to 3.7.3.

Notice with typescritp@3.2.1, the skipLibCheck does not take effect. By upgrading typescript the skipLibCheck: true works.