TS2591
TypeScriptERRORNotableTypeHIGH confidence

Cannot find name 'X'. Do you need to install type definitions for node? Try `...

Production Risk

Build will fail; resolve before shipping.

What this means

A type-checking error (TS2591): Cannot find name 'X'. 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.. This diagnostic is emitted by the TypeScript compiler when cannot find name 'X'. 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..

Why it happens
  1. 1The variable, type, or namespace is not declared in scope
  2. 2A missing import or type declaration
How to reproduce

TypeScript compiler reports TS2591 during type checking.

trigger — this will error
trigger — this will error
// Triggers TS2591
// Cannot find name 'X'. 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.

expected output

error TS2591: Cannot find name 'X'. 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.

Fix

Declare or import the missing name

WHEN When a variable or type is not in scope

Declare or import the missing name
// Add the missing import
import { MyType } from './my-module';
// Or declare the variable
const myVar: MyType = ...;

Why this works

TypeScript requires all names to be declared before use; add the missing declaration or import.

Sources
Official documentation ↗

TypeScript Compiler Diagnostics

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All TypeScript errors