TypeScript cannot find the type definition file for 'node'
error TS2688: Cannot find type definition file for 'node'.Short answer
TS2688 means tsconfig asks for the 'node' type package, and TypeScript cannot find it where it looks. Install @types/node as a dev dependency in the same project, and check that typeRoots or a parent folder does not hide node_modules/@types. Do not just delete the types line unless you do not use Node.js globals.
Fix it fast
1Find out which cause you have
Check that the package is present and see which tsconfig settings decide what is loaded.
ls node_modules/@types/node/package.json npx tsc --showConfig | grep -A4 -E '"types"|typeRoots'2Match what you see, then jump to its fix
What does the error look like?
error TS2688: Cannot find type definition file for 'node'.The file is in the program because: Entry point of type library 'node' specified in compilerOptionsCannot find name 'process'. Do you need to install type definitions for node?
Cause 1 of 2
@types/node is not installed in this project
1Check
The tsconfig names 'node' in the types array, but the package that holds those declarations was never installed.
npm ls @types/node2Fix
Install it as a dev dependency, matching your Node.js major version.
npm install --save-dev @types/node@223Verify
The compiler passes.
npx tsc --noEmitConfirmed by typescriptlang.org
Cause 2 of 2
typeRoots points somewhere that does not contain @types
1Check
Once typeRoots is set, only the folders listed there are searched, and node_modules/@types is no longer included.
grep -n -B1 -A3 typeRoots tsconfig*.json2Fix
Add node_modules/@types to the list, or remove typeRoots if you did not need it.
{
"compilerOptions": {
"typeRoots": ["./node_modules/@types", "./typings"]
}
}3Verify
Run the compiler again.
npx tsc --noEmitConfirmed by typescriptlang.org
How do I stop it coming back?
- Install @types/node in every package of a monorepo that lists 'node' in types.
- Keep the @types/node major version equal to the Node.js major you run.
- Remember that from TypeScript 6.0 the default for types is an empty list, so globals need an explicit entry.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Back end
TypeScript cannot find '@angular/platform-browser' in an Angular project
Cannot find module '@angular/platform-browser' or its corresponding type declarations.
TS2307 means TypeScript could not turn the import into a file.
3 causes, each with a fixBack end
Angular build fails with TS2707 or "has no exported member" after installing a library
Module '"@angular/core"' has no exported member
These errors mean a library was compiled by a newer Angular than your app uses.
3 causes, each with a fixBack end
cdk synth says --app is required
--app is required either in command-line, in cdk.json or in ~/.cdk.json
The CDK CLI needs a command that runs your app and finds it in three places: the --app option, cdk.json in the project folder, or cdk.json in your home folder.
3 causes, each with a fixBack end
TypeScript cannot find module '@nestjs/core' or its type declarations
error TS2307: Cannot find module '@nestjs/common' or its corresponding type declarations.
TS2307 means TypeScript searched node_modules and found neither the package nor its types.
3 causes, each with a fixBack end
Mocha or Node cannot find ts-node/register
Error: Cannot find module 'ts-node/register'
Node resolves ts-node/register from your project's node_modules, so the package must be installed there, next to typescript.
2 causes, each with a fixBack end
TypeError: Class constructor cannot be invoked without 'new' in compiled TypeScript
TypeError: Class constructors cannot be invoked without 'new'
Node.js throws this when a native class is called like a plain function.
2 causes, each with a fix