error TS2304: Cannot find name — how to fix
src/index.ts:3:1 - error TS2304: Cannot find name 'process'.
error TS2304: Cannot find name 'describe'.
error TS2304: Cannot find name 'document'.
error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
Quick fix: Install the types for the environment: npm i -D @types/node (process, require, Buffer) or @types/jest/vitest/globals (describe, it, expect). For browser globals add "dom" to compilerOptions.lib. If tsconfig has a types array, add the package there. For your own identifiers, add the missing import or declare it.
What it means
TS2304 means an identifier is used but TypeScript can't find any declaration for it in scope: no local variable, no import, no global from a .d.ts file. The code might even run fine (Node does have process), but the type checker has no declaration.
Related codes: TS2580 (Cannot find name 'require'/'process'... Do you need to install type definitions for node?), TS2582 (same for test globals like describe), and TS2583/TS2584 (Do you need to change your target library?). The fixes are the same.
Cause 1: Node globals without @types/node
process, require, module, __dirname, Buffer, setImmediate, NodeJS.Timeout:
npm install --save-dev @types/node
Then restart the TS server in your editor (VS Code: TypeScript: Restart TS Server).
Cause 2: test globals (describe, it, expect, jest)
npm install --save-dev @types/jest # Jest
npm install --save-dev @types/mocha # Mocha
For Vitest with globals: true, add the types in tsconfig:
{ "compilerOptions": { "types": ["vitest/globals"] } }
Or import them explicitly: import { describe, it, expect } from 'vitest'.
Cause 3: a types array that filters them out
If tsconfig.json has compilerOptions.types, only the listed @types packages are loaded automatically. Installing @types/node does nothing until it's listed:
{
"compilerOptions": {
"types": ["node", "jest"]
}
}
Remove the types option to load every @types/* package, or list what you need. Also check the right tsconfig applies to the file: test files are often excluded by include/exclude, or covered by a separate tsconfig.spec.json.
Cause 4: browser or newer JS globals missing from lib
document, window, HTMLElement, fetch come from the dom lib; Promise, Map, Object.entries, Array.prototype.includes and others come from ES libs. If you set lib explicitly, include what you use:
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022", "DOM", "DOM.Iterable"]
}
}
Omitting lib entirely gives you the defaults for your target, including DOM.
Cause 5: your own name is undeclared
- A typo or wrong case (
useStatevsUseState). - A missing import:
import { useState } from 'react'. - A global injected at build time (Vite
import.meta.envis fine, but__APP_VERSION__fromdefineisn't known). Declare it in a.d.tsfile included by tsconfig:
// src/globals.d.ts
declare const __APP_VERSION__: string;
- A global from a
<script>tag (e.g.gtag,google): install its types (@types/gtag.js,@types/google.maps) or declare it as above.
Cause 6: Cannot find name 'React' in JSX files
With the new JSX transform set "jsx": "react-jsx" in tsconfig instead of "react", so you don't need import React in every file.
Last updated 2026-11-08.