How to fix Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig. in TypeScript
TypeScript lacks Node types. Fix: run npm i --save-dev @types/node and add "node" to types in tsconfig.json.
Quick fix
Fixes Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
npm install --save-dev @types/node- Install @types/node package
- Verify tsconfig.json has correct compiler options
- Restart your TypeScript language server
- Verify your code can now access process object
npm install --save-dev @types/nodeCannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
npm install --save-dev @types/nodeWhat this error means
TypeScript is a statically-typed language that requires type definitions for all objects and variables you use. Node.js provides global objects like process, global, Buffer, and require that are not part of the standard JavaScript specification. When TypeScript compiles your code, it does not recognize these Node.js globals because it lacks the type information needed. This error (TS2304) indicates that the TypeScript compiler cannot find a name in scope. When accessing Node.js globals without proper type definitions, TypeScript cannot determine what these objects are, so it treats them as undefined names and raises an error during compilation.
Typical symptoms
- Error message "Cannot find name 'process'" in TypeScript files
- Unable to access process.env in your code
- Similar errors for require, global, Buffer, or other Node.js globals
- Red squiggly lines under Node.js APIs in your IDE (VS Code, WebStorm)
- Compilation fails with TS2304 error codes
- IntelliSense and autocomplete not working for process.env properties
Common causes
- @types/node package is not installed in your project dependencies
- tsconfig.json does not include "node" in the "types" array or "types" is missing entirely
- "lib" in tsconfig.json is set too restrictively and does not include necessary type definitions
- Using TypeScript in a browser/frontend environment where Node.js types should not be included
- TypeScript language server in your IDE is not reloaded after installing @types/node
- Using create-react-app or similar frontend tooling that intentionally excludes Node.js types from browser code
How to fix "Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig."
Open your terminal and install the official Node.js type definitions package. This provides TypeScript with all the type information needed to recognize Node.js globals.
npm install --save-dev @types/nodeIf you are using Yarn:
yarn add --dev @types/nodeIf you are using pnpm:
pnpm add --save-dev @types/nodeOpen your tsconfig.json file and ensure it includes "node" in the types array. If you don't have a types array, add one.
{
"compilerOptions": {
"lib": ["es2015", "dom"],
"types": ["node"]
}
}Alternatively, if you want to be more explicit about which types to include, you can reference @types/node directly:
{
"compilerOptions": {
"types": ["node", "jest"]
}
}If you omit the "types" array entirely, TypeScript will include all @types packages found in node_modules, which works for most projects.
Your IDE may be caching the old TypeScript compilation results. Restart the TypeScript language server to pick up the new type definitions.
For VS Code:
- Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P)
- Search for "TypeScript: Restart TS Server"
- Press Enter
Alternatively, reload the entire window:
- Open the Command Palette
- Search for "Developer: Reload Window"
- Press Enter
For WebStorm/IntelliJ:
- Go to File > Invalidate Caches / Restart
- Choose "Invalidate and Restart"
After installing @types/node and restarting your IDE, you should be able to use Node.js globals without errors. Test by accessing the process object:
// Now this works without TypeScript errors
console.log(process.env.NODE_ENV);
console.log(process.cwd());
console.log(process.version);
// You can also use other Node.js globals
const filepath = require("path").join(__dirname, "file.txt");If you still see errors, verify that @types/node was installed correctly by checking node_modules/@types/node exists.
If you have both Node.js server code and browser/frontend code in the same project, you may need separate tsconfig files. Create a tsconfig.node.json for server-side code:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"lib": ["es2015"],
"types": ["node"]
},
"include": ["server/**/*"],
"exclude": ["node_modules", "dist"]
}Then reference it in your build tool configuration (for example, in tsup, esbuild, or webpack) when compiling server-side code. Keep your main tsconfig.json without Node.js types for frontend code to avoid bundling unnecessary type definitions.
Create React App intentionally excludes @types/node from browser code because process is not available in the browser. If you need to access environment variables in a Create React App project, use the REACT_APP_ prefix:
// Correct for Create React App
const apiKey = process.env.REACT_APP_API_KEY;
// Define in .env file
// REACT_APP_API_KEY=your_key_hereIf you need process in backend code that runs outside Create React App (like a server file or build script), keep that code in a separate folder and use a separate tsconfig.node.json with @types/node included.
Advanced notes
In monorepo setups (using Turborepo, Nx, or Lerna), you may need to ensure @types/node is installed in the root workspace or in each package that uses Node.js APIs. Some projects use different strategies: installing @types/node as a regular dependency (not devDependency) in workspace packages that ship Node.js code, or centralizing it in the root package.json. Additionally, if you are bundling code for the browser (via Webpack, esbuild, or Vite), the bundler may provide a polyfilled process object. In that case, you still need @types/node for TypeScript compilation, but the runtime will use the bundler's process polyfill. For strict type safety, you can also use namespace declaration merging to define custom types for process.env properties in a global.d.ts file, allowing IntelliSense for your specific environment variables.
Frequently asked questions
- What does "Cannot find name 'process'. Do you need to install type definitions fo" mean?
- TypeScript is a statically-typed language that requires type definitions for all objects and variables you use. js provides global objects like process, global, Buffer, and require that are not part of the standard JavaScript specification. js globals because it lacks the type information needed.
- How do I fix "Cannot find name 'process'. Do you need to install type definitions fo"?
- TypeScript lacks Node types. Fix: run npm i --save-dev @types/node and add "node" to types in tsconfig.json.
- What causes "Cannot find name 'process'. Do you need to install type definitions fo"?
- @types/node package is not installed in your project dependencies tsconfig.json does not include "node" in the "types" array or "types" is missing entirely "lib" in tsconfig.json is set too restrictively and does not include necessary type definitions
- Is the "Cannot find name 'process'. Do you need to install type definitions fo" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐TypeScript Official Documentation
- ๐TypeScript documentation on type declarations(Official Docs)
- ๐@types/node package repository(Official Docs)
- ๐
- ๐
- ๐TypeScript tsconfig.json documentation(Official Docs)