• Error
  • Reported by the type checker

TS2584

Cannot find name '{0}'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'.

A browser global such as document is used but the DOM library isn't loaded. Add "dom" to the lib option, or don't use browser APIs in this code.

What it means

The name is a global from the browser's DOM library (for example document or window), and the project's lib option doesn't include "dom", so the checker doesn't know it.

Example

tsconfig.json
{
  "compilerOptions": {
    "strict": true,
    "target": "es2022",
    "module": "esnext",
    "moduleResolution": "bundler",
    "noEmit": true,
    "lib": [
      "es2022"
    ]
  }
}
index.ts
document.title = "x";
export {};
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(1,1): error TS2584: Cannot find name 'document'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'.

Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01.

How to fix

  • For code that runs in a browser, add "dom" to lib in tsconfig.json: "lib": ["es2022", "dom"].
  • For code that runs elsewhere (Node, a worker), use that environment's APIs instead.