TS2580
TypeScript Compiler Error
Severity: MinorWhat Does This Error Mean?
TS2580 means TypeScript does not know about the Node.js require function because the Node.js type definitions are not installed. Fix: run npm install --save-dev @types/node to add Node.js type support.
Affected Models
- TypeScript projects without @types/node
- Frontend TypeScript projects using require()
Common Causes
- @types/node not installed — TypeScript does not know about Node.js globals
- tsconfig.json types array not including node
- Using require() in a browser-targeted TypeScript file
- Mixed CommonJS and ES Module syntax in the same file
- Newly created project without Node.js type definitions
How to Fix It
-
Install Node.js type definitions: npm install --save-dev @types/node
This adds type definitions for all Node.js built-ins including require, process, __dirname, and Buffer.
-
Add node to the types array in tsconfig.json if it is not already there.
In tsconfig.json under compilerOptions, add: types: [node] This explicitly tells TypeScript to load the Node.js type definitions.
-
If this is a browser project, replace require() with ES Module import syntax.
Browser TypeScript should use: import something from 'module' instead of const something = require('module'). require() is Node.js-only and does not exist natively in browsers.
Frequently Asked Questions
Should I use require() or import in TypeScript?
Use ES Module import syntax (import x from 'y') in TypeScript — it is the modern standard and works in both Node.js and browsers. require() still works in Node.js TypeScript with @types/node installed, but import is preferred.
TS2580 appeared after upgrading TypeScript — why?
Newer TypeScript versions are stricter about ambient type declarations. If @types/node was implied before but now must be explicit, run npm install --save-dev @types/node and add it to your tsconfig.json types array.