Fix tsconfig.json 'cannot find type definition file for node'
By Flavio Copes
Fix the tsconfig.json 'cannot find type definition file for node' error by installing the @types/node package as a dev dependency and reloading VS Code.
This error means TypeScript is looking for the Node.js type definitions and can’t find them. The fix is installing the @types/node package as a dev dependency.
Run
npm i -D @types/node
#or
bun i -D @types/node
and restart VS Code (or reload the window).
Why does this error happen?
Your tsconfig.json has a types entry in compilerOptions that mentions node:
{
"compilerOptions": {
"types": ["node"]
}
}
That line tells the compiler to load the type definitions for Node.js built-ins, things like process, fs, or __dirname.
Node.js doesn’t ship its own TypeScript types. They live in a separate package, @types/node, maintained on DefinitelyTyped. The compiler expects to find it inside node_modules/@types/node.
If the package isn’t installed, TypeScript raises this error on the tsconfig.json file itself. Installing it fills the gap, and the error goes away.
The error is still there after installing
VS Code runs its own TypeScript server, and it caches what it knows about your project. After installing the package, the red squiggle can stick around.
Open the command palette and run “TypeScript: Restart TS Server”. Or reload the whole window with “Developer: Reload Window”. Either one picks up the new package.
A couple of situations to check
If the error persists, check where you ran the install. In a monorepo, the package must end up in a node_modules folder that TypeScript can resolve from the location of that tsconfig.json. Installing it at the wrong level leaves the error in place.
Also check for a typeRoots option in your config. If it points to a custom folder, TypeScript stops looking in node_modules/@types, and the freshly installed package gets ignored. If you don’t have a reason to keep typeRoots, remove it.
One more tip: you can match the types to your Node version. Running Node 22? Install @types/node@22. The major versions of the package track the major versions of Node.
If your tsconfig.json needs more fixing than that, I built a free tsconfig generator that builds a sensible config and explains every option.
Related posts about tools: