Exclude node_modules from "problems"
Asked Answered
G

3

72

I'm running this task:

{
        "taskName": "tsc watch",
        "command": "tsc -w",
        "type": "shell",
        "problemMatcher": "$tsc-watch"
}

with this tsconfig:

{
    "compileOnSave": true,
    "files": [
        "src/index.ts"
    ],
    "compilerOptions": {
        "module": "commonjs",
        "sourceMap": true,
        "outDir": "dist/"
    },
    "exclude": [
        "node_modules"
    ]
}

the file index.ts only has one line in it:

console.log('Is it working?');

And the "problems" tab is filled with HTML related warnings from random npm modules. Why? And how do i stop it?

Edit1:
I managed to find a hack that works, by excluding the node_modules folder from the explorer:

/* settings.json */
{
    "files.exclude": {
        "**/node_modules": true
    }
}

However this is a hack, and i still want a proper answer..

Gene answered 23/7, 2017 at 16:41 Comment(1)
Exclude option does not have any effect if it is used by your source code. Since it is still not excluded, you wish to suppress checking for third-party libraries. It is where the accepted anwser regarding the "skipLibCheck" option shines.Whoremaster
J
149

I stumbled upon this issue as well. The only solution I found was add the skipLibCheck option and set it to true in the compilerOptions of my tsconfig.json:

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

According to the doc, it will skip type checking of all declaration files (*.d.ts), which were the ones throwing the warnings in my case.

Judicious answered 17/8, 2017 at 20:33 Comment(2)
mmm not working for me :(Warrantee
maybe restart the service again. That helped me right after skiping the lib checkCapitulate
M
4

All you should need is a tsconfig.json with:

{
    "compilerOptions": {
        "skipLibCheck": true,
    }
}
Marxist answered 8/2, 2022 at 21:4 Comment(5)
This adds absolutely nothing to the accepted answerSorbian
Hmmm, I just realized that your answer was the better one before the last edit of the accepted answer. Sorry.Sorbian
and again, this doesn't work for me either.Overstrain
The edits on the accepted answer is really, REALLY bad for this answer. I downvoted this answer because it was copying the accepted answer, then realised the accepted answer is copying this answer.Incalescent
pretty classic StackOverflow in action :)Marxist
A
-2

I have found another "cheat" for making that problem disappear after I tried everything and nothing worked. I added at the end of the file:

export {}

This somehow worked. I am not happy with that solution but that's the only thing that worked for me.

Antheridium answered 14/5, 2022 at 16:56 Comment(1)
Where would you place this? The question is about excluding all errors originating from node_modules.Incalescent

© 2022 - 2024 — McMap. All rights reserved.