• Error
  • Reported by the type checker

TS2591

Cannot find name '{0}'. 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.

A Node.js global such as process or require isn't known. Install @types/node and add "node" to the types option in tsconfig.json.

What it means

The name is a Node.js global (process, require, Buffer, __dirname and so on), and no type definitions for Node are loaded in the project.

Example

index.ts
const env = process.env.HOME;
export {};
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(1,13): error TS2591: 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.

Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.

How to fix

  • Install the Node type definitions: npm i --save-dev @types/node.
  • If tsconfig.json sets types, add "node" to it.
  • If the code isn't meant to run on Node, use the equivalent API of its real environment.