Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force tsc to ignore node_modules folder?

People also ask

Should node_modules be ignored?

Not committing node_modules implies you need to list all your modules in the package. json (and package-lock. json ) as a mandatory step. This is great because you might not have the diligence to do so, and some of the npm operations might break if you don't.

How do I permanently delete node modules?

Just Open your root folder with VSCode. Select node_modules folder and delete. Profit. (It will take few milliseconds to delete.)


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 [email protected] and fixed by upgrading it to 3.7.3.

Notice with [email protected], the skipLibCheck does not take effect. By upgrading typescript the skipLibCheck: true works.


You can do this right on the command line

tsc --skipLibCheck

set "skipLibCheck": true inside tsconfig.json