TS2304: Cannot Find Name: What It Means and How to Fix It
Error reference
TS2304: Cannot Find Name
Language
Severity
MediumWhen it happens
TypeScript error TS2304 is reported when an identifier is used but TypeScript cannot find a declaration for it in the current scope.
Potential fixes
Import the identifier from the correct module. Install the relevant @types package for missing globals. Check for typos in names. Configure your tsconfig.json lib or types array to include the environment globals you need.
Related errors
Deep dive
TypeScript error TS2304 is reported when an identifier is used but TypeScript cannot find a declaration for it in the current scope. This is the TypeScript equivalent of a ReferenceError and is caught at compile time.
Why it happens
- •A function, variable, or type is used without being imported or declared.
- •A global type (like window, document, or process) is used without the appropriate @types package.
- •A type from a third-party library is used without installing @types for that library.
- •A typo in the identifier name.
Potential fixes
Import the identifier from the correct module. Install the relevant @types package for missing globals. Check for typos in names. Configure your tsconfig.json lib or types array to include the environment globals you need.
Examples
Code that triggers the error
const result = add(2, 3); // 'add' not importedError output
error TS2304: Cannot find name 'add'.
Fixed code
import { add } from "./math";
const result = add(2, 3);Practice in English
How would you explain a TS2304: Cannot Find Name to a fellow dev? Choose the right phrase:
"I hit an error...
Ready to practice your English at work?
Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.
Try Lingua-e for free