TypeScript error

TS2584: console is missing because lib leaves out the DOM

  • Error TS2584
  • Tested with TypeScript 5.9

error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'. is reported for console and document when the checker has no declaration for them; other browser names, such as window, are plain TS2304. console is not part of the ECMAScript standard: TypeScript declares it in its DOM library, and the Node.js types declare it for Node.js.

It appears after setting lib explicitly, for example ["es2022"] in a Node.js project, without also loading @types/node. The message's suggestion, adding dom, is right for browser code and wrong for server code.

At a glance

CodeTS2584
MessageCannot find name '{0}'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'.
TypeScript's categoryerror
Listed underUnknown names and members
Depends on lib, types
In .js files Reported when the file is checked: checkJs in jsconfig.json, or // @ts-check at the top of the file

The message is TypeScript's own text from its diagnostic messages file (Apache-2.0); {0} is filled in by tsc for each error.

What it looks like

log.js Error confirmed 5.9.3 TypeScript 5.9.3, run 21 October 2026: log.js(4,3): error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. log.js(4,3): error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. log.js(4,3): error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'. checked 21 October 2026
/** @param {string} message */
export function info(message) {
  console.log(`[info] ${message}`);error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'.
}
A lib list without "dom", and no Node.js types.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": [],
    "lib": ["es2022"]
  },
  "include": ["*.js"]
}

What causes it

  • lib lists ECMAScript libraries only, which removes the DOM library the default would include.
  • The project runs on Node.js and @types/node is not loaded (not installed, or left out of a types list).

How to fix it

Node.js code: load the Node.js types

Install @types/node and, if the config has a types list, add "node" to it. console, process and the rest then come from Node's own declarations, and browser-only names stay errors, which is what you want in server code.

log.js TypeScript 5.9.3 TypeScript 5.9.3, run 21 October 2026: No errors. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. No errors. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. No errors. checked 21 October 2026
/** @param {string} message */
export function info(message) {
  console.log(`[info] ${message}`);
}
For Node.js code, the Node.js types provide console.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": ["node"],
    "lib": ["es2022"]
  },
  "include": ["*.js"]
}

Browser code: add dom to lib

For code that runs in a page, write "lib": ["es2022", "dom"], or remove lib so it follows target with the DOM included.

log.js TypeScript 5.9.3 TypeScript 5.9.3, run 21 October 2026: No errors. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. No errors. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. No errors. checked 21 October 2026
/** @param {string} message */
export function info(message) {
  console.log(`[info] ${message}`);
}
For browser code, add "dom" to lib.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": [],
    "lib": ["es2022", "dom"]
  },
  "include": ["*.js"]
}

Gotchas

  • fetch and setTimeout without the DOM or Node.js types are plain TS2304, without the hint.
  • In a project with both browser and server code, give each folder its own config (one with dom, one with Node.js types) rather than loading both everywhere.

Sources

Last reviewed 20 October 2026.