ProjectStack
typescript

TS2304: Cannot find name 'X'

TypeScript can't find the variable, type, function, or class you're referencing. It hasn't been declared, hasn't been imported, or is out of scope at the point where you're using it.

Common causes

  • Forgot to import the variable, type, or function from another file
  • A typo in the name — TypeScript is case-sensitive
  • Using a browser global (window, document) without the dom lib in tsconfig.json
  • Using a type from a library that needs its @types package installed

How to fix it

  1. Import the missing name: import { MyClass } from './myModule'
  2. Declare it if it's a local variable you forgot: const myVar = ...
  3. Add the appropriate lib to tsconfig.json: "lib": ["dom", "es2020"] for browser globals
  4. Install the @types package: npm install --save-dev @types/node for Node.js globals like process

Example

console.log(userName); // error TS2304: Cannot find name 'userName'.

Referencing a variable that hasn't been declared or imported in the current scope

Browse more errors

The Developer Hub covers 150+ errors across Git, npm, Node.js, Python, TypeScript, and Docker — with plain-English explanations and fix steps.