typescriptvisual-studio-code

How to ignore `node_modules` folder during TypeScript build in VSCode


I'm using visual studio code IDE and typescript, how do I get it to ignore the node_modules folder during build? Or have it build .ts files on save? It is showing a lot of errors because it's trying to compile node_modules tsd.

Currently my tasks.json is

{
    "version": "0.1.0",

    // The command is tsc.
    "command": "tsc",

    // Show the output window only if unrecognized errors occur. 
    "showOutput": "silent",

    // Under windows use tsc.exe. This ensures we don't need a shell.
    "windows": {
        "command": "tsc.exe"
    },

    "isShellCommand": true,

    // args is the HelloWorld program to compile.
    "args": [],



    // use the standard tsc problem matcher to find compile problems
    // in the output.
    "problemMatcher": "$tsc"
}

Solution

  • You can now use exclude in your tsconfig.json file:

    {
        "exclude": [
            "node_modules",
        ],
        "compilerOptions": { 
            ...
        }
    }
    

    https://www.typescriptlang.org/tsconfig/#exclude

    Note it's a sibling to, not child of, compilerOptions.