Ever had your project in VS Code show you thousands of errors from files you didn't work on? This is a tricky thing with TypeScript, and it's not your fault.
You think you're looking at your project, but VS Code is looking somewhere else.
You Did Everything Right
You're working on a clean TypeScript project. You set up your tsconfig.json
like this:
{
"skipLibCheck": true,
"exclude": ["node_modules"]
}
You told TypeScript:
"Ignore node_modules
. I don't need checks there."
But then VS Code be like:
1.2k errors in @some, library
way down in node_modules
You didn’t write that stuff. You didn’t even load it yourself. Yet, your Problems tab is full.
So… what’s going on?
What VS Code Is Secretly Doing
Here’s the issue...
When you open your project, VS Code asks:
Hmm.. Which TypeScript should I use here?
If you haven't been clear, it picks its own version, not yours.
That leads to trouble.
Even a tiny difference like your project on TypeScript 5.8.2
and VS Code on 5.8.3
, can mess up how your tsconfig.json
works.
And It Gets Worse...
VS Code begins:
Not caring about your skipLibCheck
, Digging through node_modules
, Pointing out errors that aren't yours
This goes on:
🧠 You: “Hey VS Code, I’ve configured tsconfig.json
to skip node_modules
. We're good, right?”
🤖 VS Code: “Hmm... I’ll check if you told me to use your local TypeScript...”
🤖 VS Code: “Oh wait, you didn’t explicitly say so. Guess I’ll just use my built-in TypeScript.”
🧠 You: “But that ignores my settings…”
Then... TypeScript 🤸♂️ dives headfirst into node_modules
, dragging 😵💫📛 1,000 type errors behind it.
How to Take Back Control
Make VS Code follow what you set, not what it thinks.
Use the Command Palette with:
Cmd + Shift + P (or Ctrl + Shift + P)
Then:
-
Look up:
TypeScript: Select TypeScript Version
-
Pick:
Use Workspace Version
this will automatically set VS Code to use the TypeScript version from your project, not its own and it will generate .vscode/settings.json
with the following content:
{
"typescript.tsdk": "./node_modules/typescript/lib"
}
Now, you can focus on your code without the noise from node_modules
.
Happy Coding