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
| Code | TS2584 |
|---|---|
| Message | Cannot find name '{0}'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'. |
| TypeScript's category | error |
| Listed under | Unknown 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
/** @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'.
}jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": [],
"lib": ["es2022"]
},
"include": ["*.js"]
} What causes it
liblists ECMAScript libraries only, which removes the DOM library the default would include.- The project runs on Node.js and
@types/nodeis not loaded (not installed, or left out of atypeslist).
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.
/** @param {string} message */
export function info(message) {
console.log(`[info] ${message}`);
}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.
/** @param {string} message */
export function info(message) {
console.log(`[info] ${message}`);
}jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": [],
"lib": ["es2022", "dom"]
},
"include": ["*.js"]
} Gotchas
fetchandsetTimeoutwithout 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
- TSConfig Reference: lib · TypeScript
- TSConfig Reference: types · TypeScript
- diagnosticMessages.json (TypeScript 5.9.3) · TypeScript on GitHub
Last reviewed 20 October 2026.