Short answer
Install the type package for the environment: npm install --save-dev @types/node for process, require, Buffer and __dirname, and the test runner’s types (@types/jest, or vitest/globals) for describe and it. Then check tsconfig.json: from TypeScript 6.0, types defaults to an empty list, so add "node" (and your test runner) to it; on older versions a types array also limits which @types packages load; and "lib" needs "DOM" for document and window. For your own variable or a library export, the fix is an import or a typo.
Why TypeScript can’t see the name, and the fix
01
The Node.js types are not installed
“Definitions on DefinitelyTyped are also automatically published to npm under the @types scope.” TypeScript, Type declarations: DefinitelyTyped
process, require, module, Buffer and __dirname come from Node.js, not from JavaScript itself, so TypeScript needs the Node.js type package to know them. On TypeScript 6 or later, also add "node" to types in tsconfig.json.
npm install --save-dev @types/node02
A types list in tsconfig leaves the package out
“If types is specified, only packages listed will be included in the global scope.” TypeScript, TSConfig reference: types
Before TypeScript 6.0, every installed @types package loaded when types was not set. From 6.0 the default is an empty list, so you list the packages you need. Either way, once types is set only those load, so a package you just installed stays invisible until you add it.
{ "compilerOptions": { "types": ["node", "jest"] } }03
Test globals: describe, it, expect
Jest and Vitest add describe, it and expect as globals at runtime, but TypeScript only knows them from the runner’s types. For Jest install @types/jest. For Vitest, either import them from vitest in each file, or set globals: true in the Vitest config and add "vitest/globals" to types.
// Vitest, per file import { describe, it, expect } from 'vitest'; // or tsconfig.json with globals: true "types": ["vitest/globals"]04
document or window in a project without the DOM library
A lib setting in tsconfig.json without "DOM" removes browser globals such as document, window and fetch types. Add it for browser code. If the code really runs on a server, the error is right: move that code to the browser side.
{ "compilerOptions": { "lib": ["ES2022", "DOM", "DOM.Iterable"] } }
Checked against the vendor’s docs on : TypeScript: TSConfig reference (types, lib); TypeScript Handbook: Type declarations.
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.See scope and start
Related: TypeScript “Property does not exist on type” · TypeScript “Type is not assignable to type” · “require is not defined”